diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -19,8 +19,9 @@ #define EXCLUDE_PATHS ".vcxignore" -#define BUFLEN 8192 -#define MAX_DEPTH 256 +#define BUFLEN 8192 +#define MAX_DEPTH 256 +#define MAX_PATH_LEN 4096 #define KIND_DEL 'D' #define KIND_MOD 'M' @@ -126,8 +127,6 @@ static inline void add(int argc, char *argv[]) if (lstat(wt_path, &st) == -1) err(1, "%s", wt_path); - printf("Loop index %zu, path: %s\n", i, wt_path); - size_t hd_sz = strlen(HEAD) + strlen(wt_path) + 2; char hd_path[hd_sz]; concat(hd_path, hd_sz, HEAD, "/", wt_path, NULL); @@ -138,6 +137,7 @@ static inline void add(int argc, char *argv[]) if (nftw(hd_path, scan_head, MAX_DEPTH, FTW_PHYS) == -1) err(1, "Failed to scan head"); + if (nftw(wt_path, scan_tree, MAX_DEPTH, FTW_PHYS) == -1) err(1, "Failed to scan work tree"); } @@ -184,7 +184,7 @@ int scan_head(const char * path, const struct stat *sb, int flag, static inline int scan_tree(const char * path, const struct stat *st, int flag, struct FTW *ftwbuf) { - if (fnmatch("./.vcx/*", path, FNM_PATHNAME) == 0) + if (fnmatch("./.vcx/*", path, 0) == 0) return 0; if (flag == FTW_F) { @@ -302,7 +302,6 @@ static inline void stage_file(const char *file, char kind, int islnk) char lnk_path[lnkp_sz]; concat(lnk_path, lnkp_sz, TMP_DIR, "/", file, NULL); - printf("Link: %s -> %s\n", lnk_path, lnk_target); mkdirs(lnk_path); if (symlink(lnk_target, lnk_path) != 0) err(1, "symlink error on %s", file); @@ -437,17 +436,12 @@ static inline void mkdirs(const char *path) char *p; int pathlen; - static char *buf = NULL; - static size_t buflen = 1024; - - if (!buf) - buf = MALLOC(buflen); + static char buf[MAX_PATH_LEN]; pathlen = strlen(path); - if (buflen < pathlen + 1) { - buflen *= 2; - buf = REALLOC(buf, buflen); - } + if (MAX_PATH_LEN < pathlen + 1) + errx(1, "Path too long: %s", path); + buf[0] = '\0'; strcpy(buf, path); |
