disk. The wrappers check for dry_run.
.SUFFIXES: .c .o
LIBOBJ=lib/getopt.o lib/fnmatch.o lib/zlib.o lib/compat.o
-OBJS1=rsync.o exclude.o util.o md4.o main.o checksum.o match.o
+OBJS1=rsync.o exclude.o util.o md4.o main.o checksum.o match.o syscall.o
OBJS=$(OBJS1) flist.o io.o compat.o hlink.o token.o uidlist.o $(LIBOBJ)
.c.o:
if (link_stat(f_name(&hlink_list[i-1]),&st1) != 0) continue;
if (link_stat(f_name(&hlink_list[i]),&st2) != 0) {
- if (!dry_run && link(f_name(&hlink_list[i-1]),f_name(&hlink_list[i])) != 0) {
+ if (do_link(f_name(&hlink_list[i-1]),f_name(&hlink_list[i])) != 0) {
if (verbose > 0)
fprintf(FINFO,"link %s => %s : %s\n",
f_name(&hlink_list[i]),
} else {
if (st2.st_dev == st1.st_dev && st2.st_ino == st1.st_ino) continue;
- if (!dry_run && (unlink(f_name(&hlink_list[i])) != 0 ||
- link(f_name(&hlink_list[i-1]),f_name(&hlink_list[i])) != 0)) {
+ if (do_unlink(f_name(&hlink_list[i])) != 0 ||
+ do_link(f_name(&hlink_list[i-1]),f_name(&hlink_list[i])) != 0) {
if (verbose > 0)
fprintf(FINFO,"link %s => %s : %s\n",
f_name(&hlink_list[i]),
if (S_ISDIR(file->mode)) {
if (dry_run) return;
if (statret == 0 && !S_ISDIR(st.st_mode)) {
- if (unlink(fname) != 0) {
+ if (do_unlink(fname) != 0) {
fprintf(FERROR,"unlink %s : %s\n",fname,strerror(errno));
return;
}
}
}
}
- if (!dry_run) unlink(fname);
- if (!dry_run && symlink(file->link,fname) != 0) {
+ do_unlink(fname);
+ if (do_symlink(file->link,fname) != 0) {
fprintf(FERROR,"link %s -> %s : %s\n",
fname,file->link,strerror(errno));
} else {
if (statret != 0 ||
st.st_mode != file->mode ||
st.st_rdev != file->rdev) {
- if (!dry_run) unlink(fname);
+ do_unlink(fname);
if (verbose > 2)
fprintf(FERROR,"mknod(%s,0%o,0x%x)\n",
fname,(int)file->mode,(int)file->rdev);
- if (!dry_run &&
- mknod(fname,file->mode,file->rdev) != 0) {
+ if (do_mknod(fname,file->mode,file->rdev) != 0) {
fprintf(FERROR,"mknod %s : %s\n",fname,strerror(errno));
} else {
set_perms(fname,file,NULL,0);
fprintf(FERROR,"ERROR: %s is a directory\n",fname);
return;
}
- if (unlink(fname) != 0) {
+ if (do_unlink(fname) != 0) {
fprintf(FERROR,"%s : not a regular file (generator)\n",fname);
return;
}
static void delete_one(struct file_struct *f)
{
if (!S_ISDIR(f->mode)) {
- if (!dry_run && unlink(f_name(f)) != 0) {
+ if (do_unlink(f_name(f)) != 0) {
fprintf(FERROR,"unlink %s : %s\n",f_name(f),strerror(errno));
} else if (verbose) {
fprintf(FERROR,"deleting %s\n",f_name(f));
}
} else {
- if (!dry_run && rmdir(f_name(f)) != 0) {
+ if (do_rmdir(f_name(f)) != 0) {
if (errno != ENOTEMPTY)
fprintf(FERROR,"rmdir %s : %s\n",f_name(f),strerror(errno));
} else if (verbose) {
void exit_cleanup(int code)
{
if (cleanup_fname)
- unlink(cleanup_fname);
+ do_unlink(cleanup_fname);
signal(SIGUSR1, SIG_IGN);
if (code) {
kill_all(SIGUSR1);
close(fd1);
continue;
}
- fd2 = open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,file->mode);
+ fd2 = do_open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,file->mode);
if (fd2 == -1 && relative_paths && errno == ENOENT &&
create_directory_path(fnametmp) == 0) {
- fd2 = open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,file->mode);
+ fd2 = do_open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,file->mode);
}
if (fd2 == -1) {
fprintf(FERROR,"open %s : %s\n",fnametmp,strerror(errno));
} else {
set_perms(fname,file,NULL,0);
}
- unlink(fnametmp);
+ do_unlink(fnametmp);
} else {
fprintf(FERROR,"rename %s -> %s : %s\n",
fnametmp,fname,strerror(errno));
- unlink(fnametmp);
+ do_unlink(fnametmp);
}
} else {
set_perms(fname,file,NULL,0);
--- /dev/null
+/*
+ Copyright (C) Andrew Tridgell 1998
+
+ 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.
+*/
+
+/*
+ syscall wrappers to ensure that nothing gets done in dry_run mode
+ */
+
+#include "rsync.h"
+
+extern int dry_run;
+
+int do_unlink(char *fname)
+{
+ if (dry_run) return 0;
+ return unlink(fname);
+}
+
+int do_symlink(char *fname1, char *fname2)
+{
+ if (dry_run) return 0;
+ return symlink(fname1, fname2);
+}
+
+int do_link(char *fname1, char *fname2)
+{
+ if (dry_run) return 0;
+ return link(fname1, fname2);
+}
+
+int do_mknod(char *pathname, mode_t mode, dev_t dev)
+{
+ if (dry_run) return 0;
+ return mknod(pathname, mode, dev);
+}
+
+int do_rmdir(char *pathname)
+{
+ if (dry_run) return 0;
+ return rmdir(pathname);
+}
+
+int do_open(char *pathname, int flags, mode_t mode)
+{
+ if (dry_run) return -1;
+ return open(pathname, flags, mode);
+}
int set_modtime(char *fname,time_t modtime)
{
+ extern int dry_run;
+ if (dry_run) return 0;
+ {
#ifdef HAVE_UTIMBUF
- struct utimbuf tbuf;
- tbuf.actime = time(NULL);
- tbuf.modtime = modtime;
- return utime(fname,&tbuf);
+ struct utimbuf tbuf;
+ tbuf.actime = time(NULL);
+ tbuf.modtime = modtime;
+ return utime(fname,&tbuf);
#elif defined(HAVE_UTIME)
- time_t t[2];
- t[0] = time(NULL);
- t[1] = modtime;
- return utime(fname,t);
+ time_t t[2];
+ t[0] = time(NULL);
+ t[1] = modtime;
+ return utime(fname,t);
#else
- struct timeval t[2];
- t[0].tv_sec = time(NULL);
- t[0].tv_usec = 0;
- t[1].tv_sec = modtime;
- t[1].tv_usec = 0;
- return utimes(fname,t);
+ struct timeval t[2];
+ t[0].tv_sec = time(NULL);
+ t[0].tv_usec = 0;
+ t[1].tv_sec = modtime;
+ t[1].tv_usec = 0;
+ return utimes(fname,t);
#endif
+ }
}
return -1;
}
- if (unlink(dest) && errno != ENOENT) {
+ if (do_unlink(dest) && errno != ENOENT) {
fprintf(FERROR,"unlink %s: %s\n",
dest,strerror(errno));
return -1;
}
- ofd = open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode);
+ ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode);
if (ofd < 0) {
fprintf(FERROR,"open %s: %s\n",
dest,strerror(errno));