summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2011-10-14 15:11:22 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2011-10-14 15:11:22 +0100
commit87f84d4305716e73f43d0e0577b8295fdff2a64d (patch)
tree56b45a04cbb2cdabb2d18dde911ee21f27683b4a
parente330f278e2aa8fd1585c35c8f139bccb74f62d40 (diff)
downloadtbdiff-87f84d4305716e73f43d0e0577b8295fdff2a64d.tar.gz
Fixed files losing group metadata
Actually it was losing all metadata other than that which changed metadata was lost when the file was removed, but only the data that changed was applied the fix is to ignore the metadata diff mask as all the data is written to the binary diff, however it needn't be, so if it gets fixed to only send what changed, the metadata will have to be read before the file is recreated and the metadata changed based on what was sent in the binary diff
-rw-r--r--libtbd_apply.c29
-rwxr-xr-xtests/00_regular_file_diff.sh4
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 && \