separated out the make_backup code in preparation for some patches
authorAndrew Tridgell <tridge@samba.org>
Mon, 30 Aug 1999 08:19:47 +0000 (08:19 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 30 Aug 1999 08:19:47 +0000 (08:19 +0000)
from Bob Edwards

Makefile.in
backup.c [new file with mode: 0644]
rsync.c

index ec8363b..03c1ca6 100644 (file)
@@ -24,7 +24,7 @@ LIBOBJ=lib/getopt.o lib/fnmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o
 ZLIBOBJ=zlib/deflate.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o \
        zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
        zlib/zutil.o zlib/adler32.o 
-OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o main.o checksum.o match.o syscall.o log.o
+OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o main.o checksum.o match.o syscall.o log.o backup.o
 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o fileio.o
 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
 OBJS=$(OBJS1) $(OBJS2) $(DAEMON_OBJ) $(LIBOBJ) $(ZLIBOBJ)
diff --git a/backup.c b/backup.c
new file mode 100644 (file)
index 0000000..54d5fae
--- /dev/null
+++ b/backup.c
@@ -0,0 +1,46 @@
+/* 
+   Copyright (C) Andrew Tridgell 1999
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* backup handling code */
+
+#include "rsync.h"
+
+extern int verbose;
+extern char *backup_suffix;
+
+
+int make_backup(char *fname)
+{
+       char fnamebak[MAXPATHLEN];
+       if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
+               rprintf(FERROR,"backup filename too long\n");
+               return 0;
+       }
+
+       slprintf(fnamebak,sizeof(fnamebak),"%s%s",fname,backup_suffix);
+       if (do_rename(fname,fnamebak) != 0) {
+               /* cygwin (at least version b19) reports EINVAL */
+               if (errno != ENOENT && errno != EINVAL) {
+                       rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
+                       return 0;
+               }
+       } else if (verbose > 1) {
+               rprintf(FINFO,"backed up %s to %s\n",fname,fnamebak);
+       }
+       return 1;
+}
diff --git a/rsync.c b/rsync.c
index 489afcf..5a02979 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -30,7 +30,6 @@ extern int preserve_uid;
 extern int preserve_gid;
 extern int preserve_perms;
 extern int make_backups;
-extern char *backup_suffix;
 
 
 /*
@@ -232,27 +231,6 @@ void sig_int(void)
        exit_cleanup(RERR_SIGNAL);
 }
 
-int make_backup(char *fname)
-{
-       char fnamebak[MAXPATHLEN];
-       if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
-               rprintf(FERROR,"backup filename too long\n");
-               return 0;
-       }
-
-       slprintf(fnamebak,sizeof(fnamebak),"%s%s",fname,backup_suffix);
-       if (do_rename(fname,fnamebak) != 0) {
-               /* cygwin (at least version b19) reports EINVAL */
-               if (errno != ENOENT && errno != EINVAL) {
-                       rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
-                       return 0;
-               }
-       } else if (verbose > 1) {
-               rprintf(FINFO,"backed up %s to %s\n",fname,fnamebak);
-       }
-       return 1;
-}
-
 
 /* finish off a file transfer, renaming the file and setting the permissions
    and ownership */