]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
snapshot: Ensure that the snapshotdb directory is correctly created
authorEric Bollengier <eric@baculasystems.com>
Tue, 6 Jul 2021 09:59:16 +0000 (11:59 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:02 +0000 (09:03 +0100)
bacula/src/tools/bsnapshot.c

index f66b70109bb65d16afc303b0c72077f68fbf1f22..976d733fd7154f01381bc17ca55b307845ced2bc 100644 (file)
@@ -571,9 +571,26 @@ public:
    };
 
    int support() {
+      struct stat sp;
       if (!snapshot::support()) {
          return 0;
       }
+
+      if (!arg->working) {
+         printf("status=0 type=apfs error=\"Unable to use SNAPSHOT_WORKING\"\n");
+         return 0;
+      }
+
+      Mmsg(path, "%s/snapshotdb", arg->working);
+      if (stat(path, &sp) < 0) {
+         if (!makedir(path)) {
+            printf("status=%d error=\"Unable to create working database directory %s errno=%d\n",
+                   get_error_code(),
+                   arg->mountpoint, errno);
+            return 0;
+         }
+      }
+
       printf("status=1 device=\"%s\" type=apfs\n", arg->mountpoint);
       return 1;
    };
@@ -591,7 +608,7 @@ public:
       }
 
       Mmsg(path, "%s/snapshotdb", arg->working);
-      if (stat(path, &sp) != 0) {
+      if (stat(path, &sp) < 0) {
          if (!makedir(path)) {
             printf("status=%d error=\"Unable to create working database directory %s errno=%d\n",
                    get_error_code(),
@@ -676,7 +693,7 @@ public:
       FILE *fp = fopen(path, "w");
       if (!fp) {
          berrno be;
-         printf("status=0 error=\"Unable to store information about snapshot errno=%s\"\n", be.bstrerror());
+         printf("status=0 error=\"Unable to store information about snapshot in %s errno=%s\"\n", path, be.bstrerror());
          return 0;
       }
       fprintf(fp, "%s\n", fname);