Hi Dave,
> I guess I would still like to see what it looks like with just casts
> instead of the extra local variables but maybe you're right that it's
> cleaner the way you had it.
I attach an alternate patch file with just the casts.
> > 4) If using rsync to update a local mirror (ie. receive files), then the
> > total number of files deleted is also printed out with the statistics
> > (--stats). The count of files deleted at the remote site (ie. when
sending
> > files) is not printed, since to do so would require a protocol
change.
>
> That seems worthwhile, probably even enough to have a protocol change.
> Maybe you could put in the code to check for the next protocol number
> without actually changing the protocol number, so that the
> next time the
> number does change the fix will take effect. I remember
> doing something like that with a stat before...
I tried to do this, but it wasn't as simple as I thought. Sorry. The problem
is that the number of deleted files are known at the receiver, so (unless
the client is also the receiver) this number has to be transferred from
receiver to sender. That's in the opposite direction to the rest of the
statistics. I think the receiver->sender connection may already be closed at
this point.
I still think it's useful to have the count of files deleted locally, even
if we can't get that statistic for transfers in the opposite direction. I
don't know about you, but I nearly always use rsync in "pull" (rather than
"push") mode.
Tim.
PS. The attached patch file is for a virgin 2.4.3 distribution - it's not
relative to my previous patch. I have updated the comments at the beginning.
============================== cut here ==============================
Tim Adye, BaBar/DELPHI Groups, Particle Physics Dept., _ /|
Rutherford Appleton Laboratory, UK. \'o.O' Oop!
e-mail: [EMAIL PROTECTED] or VXCERN::ADYE (HEPNET/SPAN) =(___)= Ack!
WWW: http://hepwww.rl.ac.uk/Delphi/Adye/homepage.html U Thphft!
rsync-2.4.3-tja2.patch
This patch file for rsync 2.4.3 (http://rsync.samba.org/), contains the
following changes.
1) The --copy-unsafe-links option had no effect on the destination directory
tree - symlinks were never followed, even if they were absolute
(ie. started with "/"), or otherwise "unsafe".
See the quoted message below for more details on this problem.
This patch fixes the problem, except in the case when an "unsafe-symlinked"
file (not directory) is updated - the symlink is still replaced by a copy
of the file. In this respect, --copy-unsafe-links now acts like --copy-links
for "unsafe" symlinks, and like --links for "safe" symlinks (I think this
is the intended behaviour).
2) --copy-unsafe-links did not correctly identify relative symlinks that
pointed outside of the directory tree (ie. with ".."), on either source
or destination.
3) If using rsync to update a local mirror (ie. receive files), then the
total number of files deleted is also printed out with the statistics
(--stats). The count of files deleted at the remote site (ie. when sending
files) is not printed, since to do so would require a much larger change.
Binaries compiled with a similar patch are available from
http://www.slac.stanford.edu/~adye/rsync-2.4.3-tja1.Linux22.i386.tar.gz
http://www.slac.stanford.edu/~adye/rsync-2.4.3-tja1.Solaris26.sparc.tar.gz
http://www.slac.stanford.edu/~adye/rsync-2.4.3-tja1.OSF1V4.alpha.tar.gz
http://www.slac.stanford.edu/~adye/rsync-2.4.3-tja1.AIX42.tar.gz
http://www.slac.stanford.edu/~adye/rsync-2.4.3-tja1.HPUX1020.tar.gz
- Tim Adye <[EMAIL PROTECTED]> 13 June 2000.
============================== cut here ==============================
Subject: copy-unsafe-links
From: Tim Adye <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Date: Tue, 9 May 2000 21:29:53 +0100
URL: http://rsync.samba.org/listproc/rsync/May2000/0050.html
Hi,
The --copy-unsafe-links option seems to do just what I want for the source
directory tree. Unfortunately it doesn't work as I would hope if a
destination directory contains "unsafe" soft links (ie. outside of the
directory tree). These are replaced by the copies from the source. Even
worse, I cannot use --dry-run to check for this, because (for directory
links at least), this copy is not listed.
For example, if I use
rsync --dry-run -rltv --copy-unsafe-links rnode:/rdisk/ /ldisk1/
and locally in /ldisk1 I have a soft link /ldisk1/dir -> /ldisk2/dir
(because I've run out of space on /ldisk1), where /ldisk2/dir is already up
to date, then the dry run tells me that no files will be copied. However if
I remove the --dry-run, then the soft link is replaced with a new copy of
/ldisk1/dir.
If, on the other hand, I use --copy-links instead, then it works as I would
hope. However that doesn't preserve "safe" soft links.
I don't know which behaviour was intended for --copy-unsafe-links, but
--dry-run should certainly show what it's about to do (particularly since
that might be to recopy an entire directory tree). I can't think of any case
where the current behaviour (replacing "unsafe" links on the *destination*)
is what you'd want. Would it be possible for --copy-unsafe-links to be
changed (or fixed) so that it follows "unsafe" links on the destination?
(I'm mainly interested in directory links, as in the example I show above.)
[...]
============================== cut here ==============================
diff -c rsync-2.4.3-orig/flist.c rsync-2.4.3/flist.c
*** rsync-2.4.3-orig/flist.c Thu Mar 30 15:23:02 2000
--- rsync-2.4.3/flist.c Tue Jun 13 16:06:54 2000
***************
*** 102,111 ****
return -1;
}
Linkbuf[l] = 0;
! if (copy_unsafe_links && (topsrcname[0] != '\0') &&
! unsafe_symlink(Linkbuf, topsrcname)) {
! return do_stat(Path, Buffer);
}
}
return 0;
#else
--- 102,116 ----
return -1;
}
Linkbuf[l] = 0;
! if (copy_unsafe_links && unsafe_symlink(Linkbuf, (char*) Path)) {
! if (verbose > 1)
! rprintf(FINFO,"readlink_stat: %s -> %s (top=%s) - copy\n",
! Path, Linkbuf, topsrcname);
! return do_stat(Path, Buffer);
}
+ if (verbose > 1)
+ rprintf(FINFO,"readlink_stat: %s -> %s (top=%s)\n",
+ Path, Linkbuf, topsrcname);
}
return 0;
#else
***************
*** 118,126 ****
#if SUPPORT_LINKS
if (copy_links) {
return do_stat(Path, Buffer);
- } else {
- return do_lstat(Path, Buffer);
}
#else
return do_stat(Path, Buffer);
#endif
--- 123,148 ----
#if SUPPORT_LINKS
if (copy_links) {
return do_stat(Path, Buffer);
}
+ if (do_lstat(Path, Buffer) == -1) {
+ return -1;
+ }
+ if (copy_unsafe_links && S_ISLNK(Buffer->st_mode)) {
+ char Linkbuf[MAXPATHLEN];
+ int l;
+ if ((l = readlink(Path,Linkbuf,MAXPATHLEN-1)) == -1) {
+ return -1;
+ }
+ Linkbuf[l] = 0;
+ if (copy_unsafe_links && unsafe_symlink(Linkbuf, (char*) Path)) {
+ if (verbose > 1)
+ rprintf(FINFO,"link_stat: %s -> %s - follow\n", Path, Linkbuf);
+ return do_stat(Path, Buffer);
+ }
+ if (verbose > 1)
+ rprintf(FINFO,"link_stat: %s -> %s\n", Path, Linkbuf);
+ }
+ return 0;
#else
return do_stat(Path, Buffer);
#endif
Common subdirectories: rsync-2.4.3-orig/lib and rsync-2.4.3/lib
diff -c rsync-2.4.3-orig/main.c rsync-2.4.3/main.c
*** rsync-2.4.3-orig/main.c Sun Apr 9 03:53:30 2000
--- rsync-2.4.3/main.c Fri May 5 22:29:03 2000
***************
*** 75,80 ****
--- 75,83 ----
rprintf(FINFO,"\nNumber of files: %d\n", stats.num_files);
rprintf(FINFO,"Number of files transferred: %d\n",
stats.num_transferred_files);
+ if (!am_sender)
+ rprintf(FINFO,"Number of files deleted: %d\n",
+ stats.num_deleted_files);
rprintf(FINFO,"Total file size: %.0f bytes\n",
(double)stats.total_size);
rprintf(FINFO,"Total transferred file size: %.0f bytes\n",
Common subdirectories: rsync-2.4.3-orig/packaging and rsync-2.4.3/packaging
diff -c rsync-2.4.3-orig/receiver.c rsync-2.4.3/receiver.c
*** rsync-2.4.3-orig/receiver.c Thu Mar 30 15:23:03 2000
--- rsync-2.4.3/receiver.c Mon Jun 5 18:54:29 2000
***************
*** 152,157 ****
--- 152,158 ----
(void) make_backup(f);
} else {
deletion_count++;
+ stats.num_deleted_files++;
delete_one(local_file_list->files[i]);
}
}
diff -c rsync-2.4.3-orig/rsync.h rsync-2.4.3/rsync.h
*** rsync-2.4.3-orig/rsync.h Thu Mar 30 15:23:03 2000
--- rsync-2.4.3/rsync.h Fri May 5 22:27:02 2000
***************
*** 353,358 ****
--- 353,359 ----
int flist_size;
int num_files;
int num_transferred_files;
+ int num_deleted_files;
};
Common subdirectories: rsync-2.4.3-orig/zlib and rsync-2.4.3/zlib