Don't Block Removing File on Being Able to Read It

`open()`'s mode bits are only applied to files that are created by the call.
If the output file already exists, but is not readable, the `fopen()` would
fail, preventing us from removing it, which would mean that the file would
not end up with the correct permission bits.

It's not clear to me why the `fopen()` is there at all. `UTIL_isRegularFile()`
should be sufficient, AFAICT.
This commit is contained in:
W. Felix Handte
2021-05-05 13:10:34 -04:00
parent b87f97b3ea
commit 1fb10ba831
2 changed files with 28 additions and 16 deletions
+15
View File
@@ -513,6 +513,21 @@ if [ "$isWindows" = false ] ; then
rm -f tmp1.zst tmp2.zst tmp1.out tmp2.out
println "test : check permissions on pre-existing output file in compression "
chmod 0600 tmp1
touch tmp1.zst
chmod 0400 tmp1.zst
zstd -f tmp1 -o tmp1.zst
assertFilePermissions tmp1.zst 600
println "test : check permissions on pre-existing output file in decompression "
chmod 0400 tmp1.zst
touch tmp1.out
chmod 0200 tmp1.out
zstd -f -d tmp1.zst -o tmp1.out
assertFilePermissions tmp1.out 400
rm -f tmp1.zst tmp1.out
umask 0666
chmod 0666 tmp1 tmp2