From: Eric Bollengier Date: Tue, 6 Jul 2021 09:59:16 +0000 (+0200) Subject: snapshot: Ensure that the snapshotdb directory is correctly created X-Git-Tag: Release-11.3.2~465 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4297fe2cc793d37dd966570fb9a0075b53eccf7e;p=thirdparty%2Fbacula.git snapshot: Ensure that the snapshotdb directory is correctly created --- diff --git a/bacula/src/tools/bsnapshot.c b/bacula/src/tools/bsnapshot.c index f66b70109..976d733fd 100644 --- a/bacula/src/tools/bsnapshot.c +++ b/bacula/src/tools/bsnapshot.c @@ -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);