diff options
author | Cameron Katri <me@cameronkatri.com> | 2022-05-25 19:08:06 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2022-05-25 19:08:06 -0400 |
commit | 4630d99a60f87144ecd9cb392c407a316f2da30f (patch) | |
tree | b38c8932bfb3d239cbfcfcbec7843c2b45eac515 /cache_from_tree.c | |
parent | 31e664a3e50696bf19ddf27b85ad2e766967d41e (diff) | |
download | trustcache-4630d99a60f87144ecd9cb392c407a316f2da30f.tar.gz trustcache-4630d99a60f87144ecd9cb392c407a316f2da30f.tar.zst trustcache-4630d99a60f87144ecd9cb392c407a316f2da30f.zip |
nftw behaves differently on Apple systems
Diffstat (limited to 'cache_from_tree.c')
-rw-r--r-- | cache_from_tree.c | 8 |
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; |