]> git.ipfire.org Git - thirdparty/git.git/commitdiff
scalar-diagnose: add directory to archiver more gently
authorVictoria Dye <vdye@github.com>
Fri, 12 Aug 2022 20:10:11 +0000 (20:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Aug 2022 20:20:02 +0000 (13:20 -0700)
If a directory added to the 'scalar diagnose' archiver does not exist, warn
and return 0 from 'add_directory_to_archiver()' rather than failing with a
fatal error. This handles a failure edge case where the '.git/logs' has not
yet been created when running 'scalar diagnose', but extends to any
situation where a directory may be missing in the '.git' dir.

Now, when a directory is missing a warning is captured in the diagnostic
logs. This provides a user with more complete information than if 'scalar
diagnose' simply failed with an error.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/scalar/scalar.c

index 040464522841f17411e62ec42fc5fad9083efcf7..b9092f0b612eaa59174bd746b996f150f8bdb112 100644 (file)
@@ -266,14 +266,20 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
                                          const char *path, int recurse)
 {
        int at_root = !*path;
-       DIR *dir = opendir(at_root ? "." : path);
+       DIR *dir;
        struct dirent *e;
        struct strbuf buf = STRBUF_INIT;
        size_t len;
        int res = 0;
 
-       if (!dir)
+       dir = opendir(at_root ? "." : path);
+       if (!dir) {
+               if (errno == ENOENT) {
+                       warning(_("could not archive missing directory '%s'"), path);
+                       return 0;
+               }
                return error_errno(_("could not open directory '%s'"), path);
+       }
 
        if (!at_root)
                strbuf_addf(&buf, "%s/", path);