malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.23k stars 30 forks source link

"ycopy.exe -p" raises ERRORLEVEL to 1 if there is nothing to overwrite #116

Closed aleaksunder closed 8 months ago

aleaksunder commented 1 year ago

Hi!

I don't know is this an issue or not but it seems that "-p" key means to preserve existing files. So if you try to: "ycopy.exe" -p C:\file C:\existing_file or "ycopy.exe" -s -p C:\dir\* C:\existing_dir It seems for me that there is nothing to worry about if files already exists and ERRORLEVEL should not be raised to 1 or maybe should be raised to some other value like 2 or something to catch this exact situation.

malxau commented 1 year ago

I struggled a lot with what to do about errorlevel. Many tools, including copy, can be asked to do a lot of operations in a single command. In that context, what does it mean to succeed? In particular, what does copy *.c *.h c:\tmp mean if there are no .h files?

What I ended up doing was defining success as "the command successfully did at least one thing." That was in direct response to the case above, where failure to find one of the arguments isn't fatal, but failure to find all of them is. (Note that in UNIX the shell would expand these arguments, so the program being invoked has no way to know that an argument didn't expand to anything, so this behavior is trying to be consistent with that.)

It's true that this policy results in counter-intuitive behavior for the case you're describing here. But revisiting this goes back to the original problem, which is trying to distinguish expected failures from unexpected failures, where some failures return success and others are truly fatal.