Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for -r on empty directory #3027

Merged
merged 6 commits into from
Jan 29, 2022
Merged

fix for -r on empty directory #3027

merged 6 commits into from
Jan 29, 2022

Conversation

brailovich
Copy link
Contributor

fix for -r on empty directory resulted in zstd waiting for input from stdin. this fix makes zstd exit without erroring
but printing a warning message explaining that there were no files or non-empty directories to process.

-r on empty directory resulted in zstd waiting input from stdin. now zstd exits without error and prints a warning message explaining why no processing happened (no files or directories to process).
fix for error message in recursive mode for an empty folder
@terrelln
Copy link
Contributor

Thanks for the PR @brailovich!

I definitely agree with the behavior you want. We definitely don't want to use stdin when it is a TTY. There is a small question of whether we want to use stdin when it isn't a TTY. However, gzip doesn't. So I think that this behavior is fine.

programs/zstdcli.c Outdated Show resolved Hide resolved
stdin and stdout should not be used */
if (nbInputFileNames > 0 ){
DISPLAYLEVEL(2, "please provide correct input file(s) or non-empty directories -- ignored \n");
CLEAN_RETURN(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be CLEAN_RETURN(1);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if we want the CLI to return without erroring in this scenario, it should be CLEAN_RETURN(0).

@Cyan4973
Copy link
Contributor

Agreed with @terrelln comments,
this PR proposes a good behavior for the CLI.

Consider adding a test, to ensure this behavior will be preserved across future changes by future committers.

programs/zstdcli.c Outdated Show resolved Hide resolved
@brailovich
Copy link
Contributor Author

tests added, return values changed.

# combination of -r with empty folder
mkdir -p tmpEmptyDir
zstd -r tmpEmptyDir 2>tmplog2
if [grep "aborting" tmplog2]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor sh error here with [ and ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, updated!

# combination of -r with empty folder
mkdir -p tmpEmptyDir
zstd -r tmpEmptyDir 2>tmplog2
if [ grep "aborting" tmplog2 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this construction is still problematic for sh compatibility.

I'm no sh expert, and this specific construction is not used in our test script,
but I can recommend an existing idiom that has worked well so far :

zstd -r tmpEmptydir 2>&1 | grep "aborting" && die "Should not abort on empty directory"

This would be equivalent, but you could go for something even simpler :

zstd -r tmpEmptydir 

this second test only relies on return code being successful, which, I believe, is the goal of the test ?

Copy link
Contributor Author

@brailovich brailovich Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! my initial thought was to go with just zstd -r tmpEmptydir but I thought that the test should be more verbose. if this is acceptable, that's the best solution, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, "if then" sh syntax allows cleaning tmp dirs/files before exiting.

combination of -r with empty folder simplified to comply with sh compatibility tests
Copy link
Contributor

@Cyan4973 Cyan4973 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me ! Thanks @brailovich for your contribution !

@Cyan4973 Cyan4973 merged commit c9072dd into facebook:dev Jan 29, 2022
@Cyan4973 Cyan4973 mentioned this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants