Skip to content

fix for -r on empty directory #3027

Merged
Cyan4973 merged 6 commits into
facebook:devfrom
brailovich:dev
Jan 29, 2022
Merged

fix for -r on empty directory #3027
Cyan4973 merged 6 commits into
facebook:devfrom
brailovich:dev

Conversation

@brailovich

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread programs/zstdcli.c Outdated
Comment thread programs/zstdcli.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread programs/zstdcli.c Outdated
@brailovich

Copy link
Copy Markdown
Contributor Author

tests added, return values changed.

Comment thread tests/playTests.sh Outdated
# combination of -r with empty folder
mkdir -p tmpEmptyDir
zstd -r tmpEmptyDir 2>tmplog2
if [grep "aborting" tmplog2]; then

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated!

Comment thread tests/playTests.sh Outdated
# combination of -r with empty folder
mkdir -p tmpEmptyDir
zstd -r tmpEmptyDir 2>tmplog2
if [ grep "aborting" tmplog2 ]; then

Copy link
Copy Markdown
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 ?

@brailovich brailovich Jan 27, 2022

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

@Cyan4973 Cyan4973 left a comment

Copy link
Copy Markdown
Contributor

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