summaryrefslogtreecommitdiff
path: root/backup.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1999-08-30 08:19:47 +0000
committerAndrew Tridgell <tridge@samba.org>1999-08-30 08:19:47 +0000
commit3d19b4c83edab707de2ddf91b1469befc12de54e (patch)
treebfc4573278a5638831c7d38e1036f8e53565fd55 /backup.c
parent79452d46930e5e3ec5b14d4c8380ff1e0329b9a8 (diff)
downloadrsync-3d19b4c83edab707de2ddf91b1469befc12de54e.tar.gz
separated out the make_backup code in preparation for some patches
from Bob Edwards
Diffstat (limited to 'backup.c')
-rw-r--r--backup.c46
1 files changed, 46 insertions, 0 deletions
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;
+}