From: Wayne Davison Date: Fri, 24 Feb 2006 09:34:44 +0000 (+0000) Subject: Made create_directory_path() return -1 if it couldn't create some X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/85c417579f5cb56f29b9ec7d6b5509c99358a285 Made create_directory_path() return -1 if it couldn't create some portion of the filename's path. --- diff --git a/util.c b/util.c index db0275a0..dcb48f5c 100644 --- a/util.c +++ b/util.c @@ -184,28 +184,29 @@ int mkdir_defmode(char *fname) 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; } /**