X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/1ef00d2072ae5cb36282204ac2a4ada9ab4f2ff3..c4b4df4fb4cc748c1368e0c833dd5415d85071e2:/flist.c diff --git a/flist.c b/flist.c index 25db1d2b..02c58c0f 100644 --- a/flist.c +++ b/flist.c @@ -360,6 +360,7 @@ static void send_file_entry(struct file_struct *file, int f, static DEV64_T last_rdev; static uid_t last_uid; static gid_t last_gid; + static DEV64_T last_dev; static char lastname[MAXPATHLEN]; char *fname, fbuf[MAXPATHLEN]; int l1, l2; @@ -382,10 +383,19 @@ static void send_file_entry(struct file_struct *file, int f, flags |= SAME_MODE; else last_mode = file->mode; - if (file->rdev == last_rdev) - flags |= SAME_RDEV; - else - last_rdev = file->rdev; + if (preserve_devices) { + if (protocol_version < 28) { + if (IS_DEVICE(last_mode) && file->rdev == last_rdev) + flags |= OLD_SAME_RDEV|SAME_HIGH_RDEV; + else + last_rdev = file->rdev; + } + else if (IS_DEVICE(last_mode)) { + if ((file->rdev & ~0xFF) == (last_rdev & ~0xFF)) + flags |= SAME_HIGH_RDEV; + last_rdev = file->rdev; + } + } if (file->uid == last_uid) flags |= SAME_UID; else @@ -398,6 +408,15 @@ static void send_file_entry(struct file_struct *file, int f, flags |= SAME_TIME; else last_time = file->modtime; + if (file->flags & HAS_INODE_DATA) { + if (file->dev == last_dev) { + if (protocol_version >= 28) + flags |= SAME_DEV; + } + else + last_dev = file->dev; + flags |= HAS_INODE_DATA; + } for (l1 = 0; lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255); @@ -409,14 +428,22 @@ static void send_file_entry(struct file_struct *file, int f, if (l2 > 255) flags |= LONG_NAME; - /* we must make sure we don't send a zero flags byte or the other - end will terminate the flist transfer */ + /* We must make sure we don't send a zero flags byte or + * the other end will terminate the flist transfer. */ if (flags == 0 && !S_ISDIR(last_mode)) - flags |= FLAG_DELETE; - if (flags == 0) - flags |= LONG_NAME; - - write_byte(f, flags); + flags |= FLAG_DELETE; /* NOTE: no meaning for non-dir */ + if (protocol_version >= 28) { + if ((flags & 0xFF00) || flags == 0) { + flags |= EXTENDED_FLAGS; + write_byte(f, flags); + write_byte(f, flags >> 8); + } else + write_byte(f, flags); + } else { + if (flags == 0) + flags |= LONG_NAME; + write_byte(f, flags); + } if (flags & SAME_NAME) write_byte(f, l1); if (flags & LONG_NAME) @@ -438,9 +465,13 @@ static void send_file_entry(struct file_struct *file, int f, add_gid(last_gid); write_int(f, last_gid); } - if (preserve_devices && IS_DEVICE(last_mode) - && !(flags & SAME_RDEV)) - write_int(f, last_rdev); + if (preserve_devices && IS_DEVICE(last_mode)) { + /* If SAME_HIGH_RDEV is off, OLD_SAME_RDEV is also off. */ + if (!(flags & SAME_HIGH_RDEV)) + write_int(f, last_rdev); + else if (protocol_version >= 28) + write_byte(f, last_rdev); + } #if SUPPORT_LINKS if (preserve_links && S_ISLNK(last_mode)) { @@ -450,14 +481,15 @@ static void send_file_entry(struct file_struct *file, int f, #endif #if SUPPORT_HARD_LINKS - if (preserve_hard_links && S_ISREG(file->mode)) { + if (flags & HAS_INODE_DATA) { if (protocol_version < 26) { /* 32-bit dev_t and ino_t */ - write_int(f, (int) file->dev); - write_int(f, (int) file->inode); + write_int(f, last_dev); + write_int(f, file->inode); } else { /* 64-bit dev_t and ino_t */ - write_longint(f, file->dev); + if (!(flags & SAME_DEV)) + write_longint(f, last_dev); write_longint(f, file->inode); } } @@ -486,6 +518,7 @@ static void receive_file_entry(struct file_struct **fptr, static DEV64_T last_rdev; static uid_t last_uid; static gid_t last_gid; + static DEV64_T last_dev; static char lastname[MAXPATHLEN]; char thisname[MAXPATHLEN]; unsigned int l1 = 0, l2 = 0; @@ -564,13 +597,22 @@ static void receive_file_entry(struct file_struct **fptr, file->gid = last_gid; } if (preserve_devices) { - if (IS_DEVICE(last_mode)) { - if (!(flags & SAME_RDEV)) + if (protocol_version < 28) { + if (IS_DEVICE(last_mode)) { + if (!(flags & OLD_SAME_RDEV)) + last_rdev = (DEV64_T)read_int(f); + file->rdev = last_rdev; + } else + last_rdev = 0; + } else if (IS_DEVICE(last_mode)) { + if (!(flags & SAME_HIGH_RDEV)) last_rdev = (DEV64_T)read_int(f); + else { + last_rdev = (DEV64_T)((last_rdev & ~0xFF) + | read_byte(f)); + } file->rdev = last_rdev; } - else - last_rdev = 0; } if (preserve_links && S_ISLNK(last_mode)) { @@ -587,14 +629,19 @@ static void receive_file_entry(struct file_struct **fptr, sanitize_path(file->link, file->dirname); } #if SUPPORT_HARD_LINKS - if (preserve_hard_links && S_ISREG(file->mode)) { + if (preserve_hard_links && protocol_version < 28 + && S_ISREG(last_mode)) + file->flags |= HAS_INODE_DATA; + if (file->flags & HAS_INODE_DATA) { if (protocol_version < 26) { - file->dev = read_int(f); + last_dev = read_int(f); file->inode = read_int(f); } else { - file->dev = read_longint(f); + if (!(flags & SAME_DEV)) + last_dev = read_longint(f); file->inode = read_longint(f); } + file->dev = last_dev; } #endif @@ -750,8 +797,14 @@ struct file_struct *make_file(char *fname, struct string_area **ap, file->mode = st.st_mode; file->uid = st.st_uid; file->gid = st.st_gid; - file->dev = st.st_dev; - file->inode = st.st_ino; + if (preserve_hard_links) { + if (protocol_version < 28? S_ISREG(st.st_mode) + : !S_ISDIR(st.st_mode) && st.st_nlink > 1) { + file->dev = st.st_dev; + file->inode = st.st_ino; + file->flags |= HAS_INODE_DATA; + } + } #ifdef HAVE_STRUCT_STAT_ST_RDEV file->rdev = st.st_rdev; #endif @@ -1112,6 +1165,8 @@ struct file_list *recv_file_list(int f) flist_expand(flist); + if (protocol_version >= 28 && (flags & EXTENDED_FLAGS)) + flags |= read_byte(f) << 8; receive_file_entry(&flist->files[i], flags, f); if (S_ISREG(flist->files[i]->mode))