summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brewer <ben.brewer@codethink.co.uk>2014-05-29 13:55:14 (GMT)
committerBen Brewer <ben.brewer@codethink.co.uk>2014-06-02 10:03:01 (GMT)
commitfb454c327097dda283c35a911fef141382aa383f (patch)
tree3b8966f7eaa6855c0718b52437a374b710a51eca
parent9ce137fa7b1564786b93697f3ccadcd61370cd4e (diff)
downloadtbdiff-fb454c327097dda283c35a911fef141382aa383f.tar.gz
Print warning using TBD_WARN when chown failsbaserock/benbrewer/overhaul-v2
The compiler currently warns that the result of chown is ignored, for now we'll print a warning when the chown operation fails, but it'll need to be handled as an error eventually.
-rw-r--r--tbdiff/tbdiff-apply.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/tbdiff/tbdiff-apply.c b/tbdiff/tbdiff-apply.c
index 2bbc9cc..666d876 100644
--- a/tbdiff/tbdiff-apply.c
+++ b/tbdiff/tbdiff-apply.c
@@ -148,7 +148,8 @@ tbd_apply_cmd_dir_create(FILE *stream)
struct utimbuf timebuff = { time(NULL), mtime };
utime(dname, &timebuff); /* Don't care if it succeeds right now. */
- chown(dname, (uid_t)uid, (gid_t)gid);
+ if (chown(dname, (uid_t)uid, (gid_t)gid) < 0)
+ TBD_WARN("Failed to change ownership of directory");
chmod (dname, mode);
return 0;
@@ -270,7 +271,8 @@ tbd_apply_cmd_file_create(FILE *stream)
/* Don't care if it succeeds right now. */
utime(fname, &timebuff);
/* Chown ALWAYS have to be done before chmod */
- chown(fname, (uid_t)uid, (gid_t)gid);
+ if (chown(fname, (uid_t)uid, (gid_t)gid) < 0)
+ TBD_WARN("Failed to change ownership of file");
chmod(fname, mode);
return 0;
@@ -534,7 +536,8 @@ tbd_apply_cmd_symlink_create(FILE *stream)
tv[1].tv_usec = 0;
lutimes(linkname, tv); /* Don't care if it succeeds right now. */
- lchown(linkname, (uid_t)uid, (uid_t)gid);
+ if (lchown(linkname, (uid_t)uid, (uid_t)gid) < 0)
+ TBD_WARN("Failed to change ownership of symlink");
return TBD_ERROR_SUCCESS;
}
@@ -569,7 +572,8 @@ tbd_apply_cmd_special_create(FILE *stream)
struct utimbuf timebuff = { time(NULL), mtime };
utime(name, &timebuff); /* Don't care if it succeeds right now. */
- chown(name, (uid_t)uid, (gid_t)gid);
+ if (chown(name, (uid_t)uid, (gid_t)gid) < 0)
+ TBD_WARN("Failed to change ownership of node");
chmod(name, mode);
free(name);
@@ -602,8 +606,10 @@ tbd_apply_cmd_dir_delta(FILE *stream)
struct utimbuf timebuff = { time(NULL), mtime };
utime(dname, &timebuff); /* Don't care if it succeeds right now. */
}
- if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID)
- chown(dname, (uid_t)uid, (gid_t)gid);
+ if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) {
+ if (chown(dname, (uid_t)uid, (gid_t)gid) < 0)
+ TBD_WARN("Failed to change ownership during file modification");
+ }
if(metadata_mask | TBD_METADATA_MODE)
chmod(dname, mode);
@@ -637,8 +643,11 @@ tbd_apply_cmd_file_mdata_update(FILE *stream)
struct utimbuf timebuff = { time(NULL), mtime };
utime(dname, &timebuff); /* Don't care if it succeeds right now. */
}
- if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID)
- chown(dname, (uid_t)uid, (gid_t)gid);
+ if(metadata_mask & TBD_METADATA_UID || metadata_mask & TBD_METADATA_GID) {
+ if (chown(dname, (uid_t)uid, (gid_t)gid) < 0)
+ TBD_WARN("Failed to change ownership"
+ " during file attribute modification");
+ }
if(metadata_mask | TBD_METADATA_MODE)
chmod(dname, mode);