aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2022-05-25 19:08:06 -0400
committerCameron Katri <me@cameronkatri.com>2022-05-25 19:08:06 -0400
commit4630d99a60f87144ecd9cb392c407a316f2da30f (patch)
treeb38c8932bfb3d239cbfcfcbec7843c2b45eac515
parent31e664a3e50696bf19ddf27b85ad2e766967d41e (diff)
downloadtrustcache-4630d99a60f87144ecd9cb392c407a316f2da30f.tar.gz
trustcache-4630d99a60f87144ecd9cb392c407a316f2da30f.tar.zst
trustcache-4630d99a60f87144ecd9cb392c407a316f2da30f.zip
nftw behaves differently on Apple systems
-rw-r--r--cache_from_tree.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/cache_from_tree.c b/cache_from_tree.c
index 1f45e2a..610653c 100644
--- a/cache_from_tree.c
+++ b/cache_from_tree.c
@@ -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;