summaryrefslogtreecommitdiffstats
path: root/zupdate.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--zupdate.cc22
1 files changed, 13 insertions, 9 deletions
diff --git a/zupdate.cc b/zupdate.cc
index 2b88c79..2b6caaf 100644
--- a/zupdate.cc
+++ b/zupdate.cc
@@ -1,5 +1,5 @@
/* Zupdate - recompress bzip2, gzip, xz files to lzip files
- Copyright (C) 2013 Antonio Diaz Diaz.
+ Copyright (C) 2013, 2014 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -60,10 +60,10 @@ void show_help()
"appropriate for long-term data archiving.\n"
"\nIf the lzip compressed version of a file already exists, the file is\n"
"skipped unless the '--force' option is given. In this case, if the\n"
- "comparison fails, an error is returned and the original file is not\n"
- "deleted. The operation of zupdate is meant to be safe and not produce\n"
- "any data loss. Therefore, existing lzip compressed files are never\n"
- "overwritten nor deleted.\n"
+ "comparison with the existing lzip version fails, an error is returned\n"
+ "and the original file is not deleted. The operation of zupdate is meant\n"
+ "to be safe and not produce any data loss. Therefore, existing lzip\n"
+ "compressed files are never overwritten nor deleted.\n"
"\nUsage: zupdate [options] [files]\n"
"\nExit status is 0 if all the compressed files were successfully\n"
"recompressed (if needed), compared and deleted. Non-zero otherwise.\n"
@@ -105,10 +105,14 @@ int cant_execute( const std::string & command, const int status )
void set_permissions( const char * const rname, const struct stat & in_stats )
{
bool warning = false;
- // fchown will in many cases return with EPERM, which can be safely ignored.
- if( ( chown( rname, in_stats.st_uid, in_stats.st_gid ) != 0 &&
- errno != EPERM ) ||
- chmod( rname, in_stats.st_mode ) != 0 ) warning = true;
+ const mode_t mode = in_stats.st_mode;
+ // chown will in many cases return with EPERM, which can be safely ignored.
+ if( chown( rname, in_stats.st_uid, in_stats.st_gid ) == 0 )
+ { if( chmod( rname, mode ) != 0 ) warning = true; }
+ else
+ if( errno != EPERM ||
+ chmod( rname, mode & ~( S_ISUID | S_ISGID | S_ISVTX ) ) != 0 )
+ warning = true;
struct utimbuf t;
t.actime = in_stats.st_atime;
t.modtime = in_stats.st_mtime;