diff options
-rw-r--r-- | libtbd_apply.c | 29 | ||||
-rwxr-xr-x | tests/00_regular_file_diff.sh | 4 |
2 files changed, 25 insertions, 8 deletions
diff --git a/libtbd_apply.c b/libtbd_apply.c index 2e62087..a3f2b3e 100644 --- a/libtbd_apply.c +++ b/libtbd_apply.c @@ -307,15 +307,28 @@ tbd_apply_cmd_file_delta(FILE *stream) fclose(op); // Apply metadata. - if(mdata_mask & TBD_METADATA_MTIME) { - struct utimbuf timebuff = { time(NULL), mtime }; - utime(fname, &timebuff); // Don't care if it succeeds right now. + /* file was removed so old permissions were lost + * all permissions need to be reapplied, all were sent in this protocol + * if only changed sent will have to save mdata from file before it is + * removed, then change that data based on the mask + * it will still all have to be reapplied + */ + { + struct utimbuf timebuff; + timebuff.modtime = mtime; + if (time(&(timebuff.actime)) == (time_t)-1) { + return TBD_ERROR(TBD_ERROR_FAILURE); + } + if (utime(fname, &timebuff) == -1) { + return TBD_ERROR(TBD_ERROR_FAILURE); + } + if (chown(fname, (uid_t)uid, (gid_t)gid) == -1) { + return TBD_ERROR(TBD_ERROR_FAILURE); + } + if (chmod(fname, mode) == -1) { + return TBD_ERROR(TBD_ERROR_FAILURE); + } } - if(mdata_mask & TBD_METADATA_UID || - mdata_mask & TBD_METADATA_GID) - chown(fname, (uid_t)uid, (gid_t)gid); - if(mdata_mask | TBD_METADATA_MODE) - chmod(fname, mode); return 0; } diff --git a/tests/00_regular_file_diff.sh b/tests/00_regular_file_diff.sh index 3bd3310..613d924 100755 --- a/tests/00_regular_file_diff.sh +++ b/tests/00_regular_file_diff.sh @@ -15,6 +15,9 @@ ORG_FILE=$ORIGIN/b.txt TGT_FILE=$TARGET/b.txt setup () { + echo 1 >$ORIGIN/a.txt && + echo 2 >$TARGET/a.txt && + chgrp tty $ORIGIN/a.txt $TARGET/a.txt && echo 1 > $ORG_FILE && \ echo 2 > $TGT_FILE && \ chown :cdrom $TGT_FILE && \ @@ -22,6 +25,7 @@ setup () { } check_results () { + check_group $ORIGIN/a.txt tty && check_content $ORG_FILE "2" && \ check_perm $ORG_FILE 707 && \ check_group $ORG_FILE cdrom && \ |