-/* -*- c-file-style: "linux" -*-
+/*
+ * Utility routines used in rsync.
*
- * Copyright (C) 1996-2000 by Andrew Tridgell
- * Copyright (C) Paul Mackerras 1996
- * Copyright (C) 2001, 2002 by Martin Pool <mbp@samba.org>
+ * Copyright (C) 1996-2000 Andrew Tridgell
+ * Copyright (C) 1996 Paul Mackerras
+ * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
+ * Copyright (C) 2003, 2004, 2005, 2006 Wayne Davison
*
* 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
*
* 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.
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/**
- * @file
- *
- * Utilities used in rsync
- **/
-
#include "rsync.h"
extern int verbose;
int sanitize_paths = 0;
-
-
-/**
- * Set a fd into nonblocking mode
- **/
+/* Set a fd into nonblocking mode. */
void set_nonblocking(int fd)
{
int val;
}
}
-/**
- * Set a fd into blocking mode
- **/
+/* Set a fd into blocking mode. */
void set_blocking(int fd)
{
int val;
return ret;
}
-/**
- Create any necessary directories in fname. Unfortunately we don't know
- what perms to give the directory when this is called so we need to rely
- on the umask
-**/
+/* Create any necessary directories in fname. Any missing directories are
+ * created with default permissions. */
int create_directory_path(char *fname)
{
char *p;
+ int ret = 0;
while (*fname == '/')
fname++;
while (strncmp(fname, "./", 2) == 0)
fname += 2;
+ umask(orig_umask);
p = fname;
while ((p = strchr(p,'/')) != NULL) {
- *p = 0;
- mkdir_defmode(fname);
- *p = '/';
- p++;
+ *p = '\0';
+ if (do_mkdir(fname, ACCESSPERMS) < 0 && errno != EEXIST)
+ ret = -1;
+ *p++ = '/';
}
- return 0;
+ umask(0);
+
+ return ret;
}
/**
* of the path. Use -1 to allow unlimited depth.
*
* We also clean the path in a manner similar to clean_fname() but with a
- * few differences:
+ * few differences:
*
* Turns multiple adjacent slashes into a single slash, gets rid of "." dir
* elements (INCLUDING a trailing dot dir), PRESERVES a trailing slash, and