Code that was meant to trim trailing slashes from mkdir() paths
[rsync/rsync.git] / syscall.c
index dbac7dc..b4b581b 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -1,5 +1,6 @@
 /* 
    Copyright (C) Andrew Tridgell 1998
+   Copyright (C) 2002 by Martin Pool
    
    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
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-/*
-  syscall wrappers to ensure that nothing gets done in dry_run mode
-  */
+/**
+ * @file syscall.c
+ *
+ * Syscall wrappers to ensure that nothing gets done in dry_run mode
+ * and to handle system peculiarities.
+ **/
 
 #include "rsync.h"
 
@@ -106,13 +110,32 @@ int do_rename(char *fname1, char *fname2)
        return rename(fname1, fname2);
 }
 
+
+void trim_trailing_slashes(char *name)
+{
+       char *p;
+       /* Some BSD systems cannot make a directory if the name
+        * contains a trailing slash.
+        * <http://www.opensource.apple.com/bugs/X/BSD%20Kernel/2734739.html> */
+       if (!*name)
+               return;         /* empty string */
+       p = strchr(name, '\0') - 1;
+       while (p == '/') {
+               p-- = '\0';
+       }
+}
+
+
 int do_mkdir(char *fname, mode_t mode)
 {
-       if (dry_run) return 0;
-       CHECK_RO
+       if (dry_run)
+               return 0;
+       CHECK_RO;
+       trim_trailing_slashes(fname);   
        return mkdir(fname, mode);
 }
 
+
 /* like mkstemp but forces permissions */
 int do_mkstemp(char *template, mode_t perms)
 {