a couple more system calls wrapped in syscall.c
authorAndrew Tridgell <tridge@samba.org>
Sun, 5 Apr 1998 06:26:24 +0000 (06:26 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 5 Apr 1998 06:26:24 +0000 (06:26 +0000)
main.c
rsync.c
syscall.c
util.c

diff --git a/main.c b/main.c
index 41d8a6b0af713f87ee7c5c624fd12bb70521e63e..baae9d44868997b3f57e01187dbc3f73fb2efae7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -296,7 +296,7 @@ static char *get_local_name(struct file_list *flist,char *name)
   if (!name) 
     return NULL;
 
   if (!name) 
     return NULL;
 
-  if (mkdir(name,0777 & ~orig_umask) != 0) {
+  if (do_mkdir(name,0777 & ~orig_umask) != 0) {
     fprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno));
     exit_cleanup(1);
   } else {
     fprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno));
     exit_cleanup(1);
   } else {
diff --git a/rsync.c b/rsync.c
index 7776ed0eb4c6588720bb5ee2177f05b7961a0c57..cf57296a0bf7253de2cf8e1af1a8adefc72d7dd4 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -384,10 +384,10 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
       }
       statret = -1;
     }
       }
       statret = -1;
     }
-    if (statret != 0 && mkdir(fname,file->mode) != 0 && errno != EEXIST) {
+    if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) {
            if (!(relative_paths && errno==ENOENT && 
                  create_directory_path(fname)==0 && 
            if (!(relative_paths && errno==ENOENT && 
                  create_directory_path(fname)==0 && 
-                 mkdir(fname,file->mode)==0)) {
+                 do_mkdir(fname,file->mode)==0)) {
                    fprintf(FERROR,"mkdir %s : %s (2)\n",
                            fname,strerror(errno));
            }
                    fprintf(FERROR,"mkdir %s : %s (2)\n",
                            fname,strerror(errno));
            }
@@ -834,7 +834,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
       } else {
              sprintf(fnametmp,"%s.XXXXXX",fname);
       }
       } else {
              sprintf(fnametmp,"%s.XXXXXX",fname);
       }
-      if (NULL == mktemp(fnametmp)) {
+      if (NULL == do_mktemp(fnametmp)) {
        fprintf(FERROR,"mktemp %s failed\n",fnametmp);
        receive_data(f_in,buf,-1,NULL);
        if (buf) unmap_file(buf);
        fprintf(FERROR,"mktemp %s failed\n",fnametmp);
        receive_data(f_in,buf,-1,NULL);
        if (buf) unmap_file(buf);
@@ -878,14 +878,14 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
                continue;
        }
        sprintf(fnamebak,"%s%s",fname,backup_suffix);
                continue;
        }
        sprintf(fnamebak,"%s%s",fname,backup_suffix);
-       if (rename(fname,fnamebak) != 0 && errno != ENOENT) {
+       if (do_rename(fname,fnamebak) != 0 && errno != ENOENT) {
          fprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
          continue;
        }
       }
 
       /* move tmp file over real file */
          fprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
          continue;
        }
       }
 
       /* move tmp file over real file */
-      if (rename(fnametmp,fname) != 0) {
+      if (do_rename(fnametmp,fname) != 0) {
              if (errno == EXDEV) {
                      /* rename failed on cross-filesystem link.  
                         Copy the file instead. */
              if (errno == EXDEV) {
                      /* rename failed on cross-filesystem link.  
                         Copy the file instead. */
index 1893be6191e2dd748ed5ab710909f2b8bd485fa6..315285903cc1207afd10dd249a3263d142f533c5 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -77,3 +77,21 @@ int do_chmod(const char *path, mode_t mode)
        return chmod(path, mode);
 }
 #endif
        return chmod(path, mode);
 }
 #endif
+
+int do_rename(char *fname1, char *fname2)
+{
+       if (dry_run) return 0;
+       return rename(fname1, fname2);
+}
+
+int do_mkdir(char *fname, mode_t mode)
+{
+       if (dry_run) return 0;
+       return mkdir(fname, mode);
+}
+
+char *do_mktemp(char *template)
+{
+       if (dry_run) return NULL;
+       return mktemp(template);
+}
diff --git a/util.c b/util.c
index 1a041a3f5bd1adaeda778b64edc964e24fabf076..f61e91dad8571703d78864756431a83f1aa0bee6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -298,7 +298,7 @@ int create_directory_path(char *fname)
        p = fname;
        while ((p=strchr(p,'/'))) {
                *p = 0;
        p = fname;
        while ((p=strchr(p,'/'))) {
                *p = 0;
-               mkdir(fname,0777 & ~orig_umask); 
+               do_mkdir(fname,0777 & ~orig_umask); 
                *p = '/';
                p++;
        }
                *p = '/';
                p++;
        }