From 3d19b4c83edab707de2ddf91b1469befc12de54e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 30 Aug 1999 08:19:47 +0000 Subject: [PATCH] separated out the make_backup code in preparation for some patches from Bob Edwards --- Makefile.in | 2 +- backup.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ rsync.c | 22 ---------------------- 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 backup.c diff --git a/Makefile.in b/Makefile.in index ec8363b5..03c1ca63 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 index 00000000..54d5fae8 --- /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 489afcf1..5a02979e 100644 --- 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 */ -- 2.34.1