#define FNSPACE 30
/* Default file permissions 0666 (modulated by umask) */
+/* Temporary restricted file permissions are used when we're going to
+ * chmod/chown at the end of the operation. */
#if !defined(_WIN32)
/* These macros aren't defined on windows. */
#define DEFAULT_FILE_PERMISSIONS (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
+#define TEMPORARY_FILE_PERMISSIONS (S_IRUSR|S_IWUSR)
#else
#define DEFAULT_FILE_PERMISSIONS (0666)
+#define TEMPORARY_FILE_PERMISSIONS (0600)
#endif
/*-************************************
{
int closeDstFile = 0;
int result;
- int transferMTime = 0;
+ int transferStat = 0;
FILE *dstFile;
assert(AIO_ReadPool_getFile(ress.readCtx) != NULL);
if (AIO_WritePool_getFile(ress.writeCtx) == NULL) {
- int dstFilePermissions = DEFAULT_FILE_PERMISSIONS;
+ int dstFileInitialPermissions = DEFAULT_FILE_PERMISSIONS;
if ( strcmp (srcFileName, stdinmark)
&& strcmp (dstFileName, stdoutmark)
&& UTIL_isRegularFileStat(srcFileStat) ) {
- dstFilePermissions = srcFileStat->st_mode;
- transferMTime = 1;
+ transferStat = 1;
+ dstFileInitialPermissions = TEMPORARY_FILE_PERMISSIONS;
}
closeDstFile = 1;
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: opening dst: %s \n", dstFileName);
- dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName, dstFilePermissions);
+ dstFile = FIO_openDstFile(fCtx, prefs, srcFileName, dstFileName, dstFileInitialPermissions);
if (dstFile==NULL) return 1; /* could not open dstFileName */
AIO_WritePool_setFile(ress.writeCtx, dstFile);
/* Must only be added after FIO_openDstFile() succeeds.
DISPLAYLEVEL(1, "zstd: %s: %s \n", dstFileName, strerror(errno));
result=1;
}
- if (transferMTime) {
- UTIL_utime(dstFileName, srcFileStat);
+ if (transferStat) {
+ UTIL_setFileStat(dstFileName, srcFileStat);
}
if ( (result != 0) /* operation failure */
&& strcmp(dstFileName, stdoutmark) /* special case : don't remove() stdout */
{
int result;
int releaseDstFile = 0;
- int transferMTime = 0;
-
- (void)srcFileStat;
+ int transferStat = 0;
if ((AIO_WritePool_getFile(ress.writeCtx) == NULL) && (prefs->testMode == 0)) {
FILE *dstFile;
if ( strcmp(srcFileName, stdinmark) /* special case : don't transfer permissions from stdin */
&& strcmp(dstFileName, stdoutmark)
&& UTIL_isRegularFileStat(srcFileStat) ) {
- dstFilePermissions = srcFileStat->st_mode;
- transferMTime = 1;
+ transferStat = 1;
+ dstFilePermissions = TEMPORARY_FILE_PERMISSIONS;
}
releaseDstFile = 1;
result = 1;
}
- if (transferMTime) {
- UTIL_utime(dstFileName, srcFileStat);
+ if (transferStat) {
+ UTIL_setFileStat(dstFileName, srcFileStat);
}
if ( (result != 0) /* operation failure */
zstd -f -d tmp1.zst -o tmp1.out
assertFilePermissions tmp1.out 400
- rm -f tmp1.zst tmp1.out
-
umask 0666
chmod 0666 tmp1 tmp2
- println "test : respect umask when copying permissions in file -> file compression "
- zstd -f tmp1 -o tmp1.zst
- assertFilePermissions tmp1.zst 0
- println "test : respect umask when copying permissions in file -> file decompression "
- chmod 0666 tmp1.zst
- zstd -f -d tmp1.zst -o tmp1.out
- assertFilePermissions tmp1.out 0
-
rm -f tmp1.zst tmp1.out
println "test : respect umask when compressing from stdin input "