NCNN Backend Path Validation#
The upscayl-ncnn binary β the C++ processing backend powering Upscayl β enforces a strict rule: input and output paths must be the same type. Both must be files, or both must be directories. Mixing types (e.g., a file input with a directory output) causes the binary to exit with an error.
This validation lives entirely in the binary, not in the Electron main process.
Where the Rule Is Enforced#
The check is in upscayl-ncnn/src/main.cpp in the path-collection block after argument parsing. The logic uses path_is_directory() to test both paths and branches into three cases :
| Input type | Output type | Result |
|---|---|---|
| Directory | Directory | Lists input dir β writes each output file into output dir |
| File | File | Processes the single file to the single output path |
| Mixed | Mixed | Exits with error: "Input path and Output path both must be either a file or a directory!" |
The error message printed to stderr is:
π¨ Error: Input path and Output path both must be either a file or a directory!
How the Electron Layer Satisfies This Rule#
The Upscayl Electron layer avoids triggering the mismatch error by construction β each upscale mode always passes matching path types to the binary.
Single-image mode (electron/commands/image-upscayl.ts) constructs a full output file path (outFile) by concatenating the output directory, a filename suffix, and the target extension. getSingleImageArguments then passes -i <dir>/<filename> (a file path) and -o <outFile> (a file path) β file-to-file.
Batch mode (electron/commands/batch-upscayl.ts) decodes the input folder path and creates a named output subdirectory, then calls getBatchArguments with -i <inputDir> and -o <outputDir> β directory-to-directory.
Double upscale follows the same single-image pattern for both passes .
There is no runtime filesystem type check (fs.statSync, isDirectory(), etc.) in the Electron layer before invoking the binary. The contract is maintained structurally through the separation of upscale modes. If paths are malformed or point to the wrong type of filesystem entry, the error surfaces from the binary's stderr and is forwarded to the UI via the UPSCAYL_ERROR IPC event .
Binary Invocation#
The binary is spawned by spawnUpscayl via Node.js child_process.spawn. Empty argument strings are filtered out before being passed . stderr output from the binary is used for both progress reporting and error detection β the onData handler checks for the strings "Error" or "failed" to identify failures .
Key Files#
| File | Role |
|---|---|
upscayl-ncnn/src/main.cpp | Path type validation and the mismatch error |
electron/utils/get-arguments.ts | Argument builders for all upscale modes |
electron/commands/image-upscayl.ts | Single-image path construction |
electron/commands/batch-upscayl.ts | Batch (directory) path construction |
electron/utils/spawn-upscayl.ts | Binary process spawning |