]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/makepath.c
kes When applying a storage override, release all previous storage
[bacula/bacula] / bacula / src / findlib / makepath.c
index dbb873b2baaeb0837483fc4cc38e0cc8bfc9a326..87926a005556cd82a7813a2031e765819fc1735f 100644 (file)
@@ -17,7 +17,6 @@
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Written by David MacKenzie <djm@gnu.ai.mit.edu> and Jim Meyering.  */
-
 /*
  *   Modified by Kern Sibbald for use in Bacula, December 2000
  *
@@ -83,7 +82,7 @@ cleanup(struct saved_cwd *cwd)
 
 /* Attempt to create directory DIR (aka DIRPATH) with the specified MODE.
    If CREATED_DIR_P is non-NULL, set *CREATED_DIR_P to non-zero if this
-   function creates DIR and to zero otherwise. Give a diagnostic and
+   function creates DIR and to zero otherwise.  Give a diagnostic and
    return non-zero if DIR cannot be created or cannot be determined to
    exist already.  Use DIRPATH in any diagnostic, not DIR.
    Note that if DIR already exists, this function will return zero
@@ -104,7 +103,7 @@ make_dir(JCR *jcr, const char *dir, const char *dirpath, mode_t mode, int *creat
       struct stat stats;
 
       /* The mkdir and stat calls below may appear to be reversed.
-         They are not. It is important to call mkdir first and then to
+         They are not.  It is important to call mkdir first and then to
          call stat (to distinguish the three cases) only if mkdir fails.
          The alternative to this approach is to `stat' each directory,
          then to call mkdir if it doesn't exist.  But if some other process
@@ -115,7 +114,7 @@ make_dir(JCR *jcr, const char *dir, const char *dirpath, mode_t mode, int *creat
           berrno be;
           be.set_errno(save_errno);
           Jmsg(jcr, M_ERROR, 0, _("Cannot create directory %s: ERR=%s\n"),
-                  dirpath, be.strerror());
+                  dirpath, be.bstrerror());
           fail = 1;
       } else if (!S_ISDIR(stats.st_mode)) {
           Jmsg(jcr, M_ERROR, 0, _("%s exists but is not a directory\n"), quote(dirpath));
@@ -137,9 +136,9 @@ int
 isAbsolute(const char *path)
 {
 #if defined(HAVE_WIN32)
-    return path[1] == ':' || *path == '/' || *path == '\\';     /* drivespec:/blah is absolute */
+    return path[1] == ':' || IsPathSeparator(*path);     /* drivespec:/blah is absolute */
 #else
-    return *path == '/';
+    return IsPathSeparator(*path);
 #endif
 }
 
@@ -241,7 +240,7 @@ make_path(
       }
 #else
       /* If we can record the current working directory, we may be able
-         to do the chdir optimization. */
+         to do the chdir optimization.  */
       cwd.do_chdir = !save_cwd(&cwd);
 
       slash = dirpath;
@@ -255,31 +254,19 @@ make_path(
       }
 
       /* Skip over leading slashes.  */
-#if defined(HAVE_WIN32)
-      while (*slash == '/' || *slash == '\\')
+      while (IsPathSeparator(*slash))
          slash++;
-#else
-      while (*slash == '/')
-         slash++;
-#endif
-      while (1) {
+
+      for ( ; ; ) {
           int newly_created_dir;
           int fail;
 
           /* slash points to the leftmost unprocessed component of dirpath.  */
           basename_dir = slash;
-
-#if defined(HAVE_WIN32)
-          slash = strpbrk(slash, ":/\\");
+          slash = first_path_separator(slash);
           if (slash == NULL) {
              break;
           }
-#else
-          slash = strchr (slash, '/');
-          if (slash == NULL) {
-             break;
-          }
-#endif
 
           /* If we're *not* doing chdir before each mkdir, then we have to refer
              to the target using the full (multi-component) directory name.  */
@@ -307,7 +294,7 @@ make_path(
                  /* Note, if we are restoring as NON-root, this may not be fatal */
                  berrno be;
                  Jmsg(jcr, M_ERROR, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
-                      quote(dirpath), be.strerror());
+                      quote(dirpath), be.bstrerror());
               }
               Dmsg0(300, "Chown done.\n");
 
@@ -328,7 +315,7 @@ make_path(
           if (cwd.do_chdir && chdir(basename_dir) < 0) {
               berrno be;
               Jmsg(jcr, M_ERROR, 0, _("Cannot chdir to directory, %s: ERR=%s\n"),
-                     quote(dirpath), be.strerror());
+                     quote(dirpath), be.bstrerror());
               umask(oldmask);
               cleanup(&cwd);
               return 1;
@@ -338,13 +325,8 @@ make_path(
 
           /* Avoid unnecessary calls to `stat' when given
              pathnames containing multiple adjacent slashes.  */
-#if defined(HAVE_WIN32)
-         while (*slash == '/' || *slash == '\\')
-            slash++;
-#else
-         while (*slash == '/')
+         while (IsPathSeparator(*slash))
             slash++;
-#endif
       } /* end while (1) */
 
       if (!cwd.do_chdir) {
@@ -373,7 +355,7 @@ make_path(
             {
               berrno be;
               Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
-                     quote(dirpath), be.strerror());
+                     quote(dirpath), be.bstrerror());
             }
       }
 
@@ -388,7 +370,7 @@ make_path(
       if ((mode & ~S_IRWXUGO) && chmod(basename_dir, mode)) {
           berrno be;
           Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
-             quote(dirpath), be.strerror());
+             quote(dirpath), be.bstrerror());
       }
 
      if (cleanup(&cwd)) {
@@ -404,7 +386,7 @@ make_path(
           if (chmod(dirpath, parent_mode)) {
               berrno be;
               Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
-                     quote(dirpath), be.strerror());
+                     quote(dirpath), be.bstrerror());
           }
       }
   } else {
@@ -433,12 +415,12 @@ make_path(
               ) {
               berrno be;
               Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
-                     quote(dirpath), be.strerror());
+                     quote(dirpath), be.bstrerror());
             }
           if (chmod(dirpath, mode)) {
               berrno be;
               Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
-                                 quote(dirpath), be.strerror());
+                                 quote(dirpath), be.bstrerror());
           }
           Dmsg2(300, "pathexists chmod mode=%o dir=%s\n", mode, dirpath);
       }