]> git.cameronkatri.com Git - trustcache.git/commitdiff
nftw behaves differently on Apple systems
authorCameron Katri <me@cameronkatri.com>
Wed, 25 May 2022 23:08:06 +0000 (19:08 -0400)
committerCameron Katri <me@cameronkatri.com>
Wed, 25 May 2022 23:08:06 +0000 (19:08 -0400)
cache_from_tree.c

index 1f45e2ab17420fe192d35dcabc03bacc54b4da51..610653c7743c4e0fe4e992ec0e03e2399709c6d0 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #define _XOPEN_SOURCE 500
+#include <errno.h>
 #include <ftw.h>
 #include <stdio.h>
 #include <string.h>
@@ -77,10 +78,17 @@ cache_from_tree(const char *path, uint32_t version)
        ret.version = version;
 
        if (nftw(path, tccallback, 20, 0) == -1) {
+               // on macOS, nftw(3) will fail if the path is not a directory, but we don't want that
+               if (errno == ENOTDIR) {
+                       struct stat sb;
+                       if (stat(path, &sb) == 0 && tccallback(path, &sb, 0, NULL) == 0)
+                               goto done;
+               }
                perror("nftw");
                return ret;
        }
 
+done:
        ret.num_entries = cache.num_entries;
        ret.hashes = cache.hashes;
        return ret;