Switch over to Matt's idea of using FLAG_OWNED_BY_US.
authorWayne Davison <wayned@samba.org>
Sun, 30 Jan 2011 06:10:43 +0000 (22:10 -0800)
committerWayne Davison <wayned@samba.org>
Sun, 30 Jan 2011 06:19:14 +0000 (22:19 -0800)
flist.c
generator.c
rsync.h

diff --git a/flist.c b/flist.c
index 59109bccce9dec0ed097bd0ea0cdffee88a39ad2..7dec152854105493ff88842569556e3116f056de 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -67,6 +67,7 @@ extern int use_safe_inc_flist;
 extern int need_unsorted_flist;
 extern int sender_symlink_iconv;
 extern int unsort_ndx;
+extern uid_t our_uid;
 extern struct stats stats;
 extern char *filesfrom_host;
 
@@ -1227,9 +1228,6 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
        linkname_len = 0;
 #endif
 
-       if (!uid_ndx && flags & FLAG_DEL_NEEDS_UID)
-               extra_len += EXTRA_LEN;
-
 #if SIZEOF_CAPITAL_OFF_T >= 8
        if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode))
                extra_len += EXTRA_LEN;
@@ -1286,12 +1284,12 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
        }
 #endif
        file->mode = st.st_mode;
-       if (uid_ndx) /* Check uid_ndx instead of preserve_uid for del support */
+       if (preserve_uid)
                F_OWNER(file) = st.st_uid;
-       else if (flags & FLAG_DEL_NEEDS_UID)
-               F_DEL_OWNER(file) = st.st_uid;
-       if (gid_ndx) /* Check gid_ndx instead of preserve_gid for del support */
+       if (preserve_gid)
                F_GROUP(file) = st.st_gid;
+       if (am_generator && st.st_uid == our_uid)
+               file->flags |= FLAG_OWNED_BY_US;
 
        if (basename != thisname)
                file->dirname = lastdir;
@@ -3066,8 +3064,7 @@ struct file_list *get_dirlist(char *dirname, int dlen, int flags)
 
        recurse = 0;
        xfer_dirs = 1;
-       send_directory(senddir_fd, dirlist, dirname, dlen,
-                      FLAG_CONTENT_DIR | (flags & GDL_DEL_NEEDS_UID ? FLAG_DEL_NEEDS_UID : 0));
+       send_directory(senddir_fd, dirlist, dirname, dlen, FLAG_CONTENT_DIR);
        xfer_dirs = save_xfer_dirs;
        recurse = save_recurse;
        if (do_progress)
index dd23100179976051f3682069c7c7945d62edc4ed..0c3060458deba2d6ba9aeec9ac97c5d4ac2dbe88 100644 (file)
@@ -251,7 +251,7 @@ static enum delret delete_dir_contents(char *fname, uint16 flags)
        save_filters = push_local_filters(fname, dlen);
 
        non_perishable_cnt = 0;
-       dirlist = get_dirlist(fname, dlen, GDL_DEL_NEEDS_UID);
+       dirlist = get_dirlist(fname, dlen, 0);
        ret = non_perishable_cnt ? DR_NOT_EMPTY : DR_SUCCESS;
 
        if (!dirlist->used)
@@ -273,7 +273,6 @@ static enum delret delete_dir_contents(char *fname, uint16 flags)
 
        for (j = dirlist->used; j--; ) {
                struct file_struct *fp = dirlist->files[j];
-               uid_t fp_owner = uid_ndx ? F_OWNER(fp) : F_DEL_OWNER(fp);
 
                if (fp->flags & FLAG_MOUNT_DIR && S_ISDIR(fp->mode)) {
                        if (verbose > 1) {
@@ -286,7 +285,7 @@ static enum delret delete_dir_contents(char *fname, uint16 flags)
                }
 
                strlcpy(p, fp->basename, remainder);
-               if (!(fp->mode & S_IWUSR) && !am_root && fp_owner == our_uid)
+               if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US)
                        do_chmod(fname, fp->mode | S_IWUSR);
                /* Save stack by recursing to ourself directly. */
                if (S_ISDIR(fp->mode)) {
@@ -495,7 +494,7 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
                        return;
        }
 
-       dirlist = get_dirlist(fbuf, dlen, GDL_DEL_NEEDS_UID);
+       dirlist = get_dirlist(fbuf, dlen, 0);
 
        /* If an item in dirlist is not found in flist, delete it
         * from the filesystem. */
@@ -514,8 +513,7 @@ static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
                 * a delete_item call with a DEL_MAKE_ROOM flag. */
                if (flist_find_ignore_dirness(cur_flist, fp) < 0) {
                        int flags = DEL_RECURSE;
-                       uid_t fp_owner = uid_ndx ? F_OWNER(fp) : F_DEL_OWNER(fp);
-                       if (!(fp->mode & S_IWUSR) && !am_root && fp_owner == our_uid)
+                       if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US)
                                flags |= DEL_NO_UID_WRITE;
                        f_name(fp, delbuf);
                        if (delete_during == 2) {
diff --git a/rsync.h b/rsync.h
index f7b208b8fea288fe18195553509b9f636d835443..e6238de3d4eae116799041a84138f5a4bbb17431 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -65,6 +65,7 @@
 /* These flags are used in the live flist data. */
 
 #define FLAG_TOP_DIR (1<<0)    /* sender/receiver/generator */
+#define FLAG_OWNED_BY_US (1<<0) /* generator: set by make_file() for aux flists only */
 #define FLAG_FILE_SENT (1<<1)  /* sender/receiver/generator */
 #define FLAG_DIR_CREATED (1<<1)        /* generator */
 #define FLAG_CONTENT_DIR (1<<2)        /* sender/receiver/generator */
 
 /* These flags are passed to functions but not stored. */
 
-#define FLAG_DIVERT_DIRS (1<<16)/* sender, but must be unique */
-#define FLAG_DEL_NEEDS_UID (1<<17)/* generator, but must be unique */
+#define FLAG_DIVERT_DIRS (1<<16)   /* sender, but must be unique */
 
 /* These flags are for get_dirlist(). */
 #define GDL_IGNORE_FILTER_RULES (1<<0)
-#define GDL_DEL_NEEDS_UID (1<<1)
 
+/* Some helper macros for matching bits. */
 #define BITS_SET(val,bits) (((val) & (bits)) == (bits))
 #define BITS_SETnUNSET(val,onbits,offbits) (((val) & ((onbits)|(offbits))) == (onbits))
 #define BITS_EQUAL(b1,b2,mask) (((unsigned)(b1) & (unsigned)(mask)) \
 
 /* This is used when working on a new protocol version in CVS, and should
  * be a new non-zero value for each CVS change that affects the protocol.
- * It must ALWAYS be 0 when the protocol goes final! */
+ * It must ALWAYS be 0 when the protocol goes final (and NEVER before)! */
 #define SUBPROTOCOL_VERSION 0
 
 /* We refuse to interoperate with versions that are not in this range.
@@ -700,10 +700,6 @@ extern int xattrs_ndx;
 #define F_SUM(f) ((char*)OPT_EXTRA(f, LEN64_BUMP(f) + HLINK_BUMP(f) \
                                    + SUM_EXTRA_CNT - 1))
 
-/* When deleting w/o --owner, we put the UID info last (like F_SUM(), but smaller).
- * This is OK, because delete lists never need checksums. */
-#define F_DEL_OWNER(f) OPT_EXTRA(f, LEN64_BUMP(f) + HLINK_BUMP(f))->unum
-
 /* Some utility defines: */
 #define F_IS_ACTIVE(f) (f)->basename[0]
 #define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED)