diff options
author | koekeishiya <aasvi93@hotmail.com> | 2018-07-20 11:48:50 +0200 |
---|---|---|
committer | koekeishiya <aasvi93@hotmail.com> | 2018-07-20 11:48:50 +0200 |
commit | b64de269a73c2e3cc820d29f5dd9c10c42a1ee36 (patch) | |
tree | f0ec32ac755b9741c703c7dbd25a607a08b9ee6b /src/hotload.c | |
parent | 3bbbd37c796eb7039247cb1625608062dcc898e7 (diff) | |
download | skhd-b64de269a73c2e3cc820d29f5dd9c10c42a1ee36.tar.gz skhd-b64de269a73c2e3cc820d29f5dd9c10c42a1ee36.zip |
hotloader: properly resolve file kind
Diffstat (limited to '')
-rw-r--r-- | src/hotload.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/hotload.c b/src/hotload.c index 6610609..f925d53 100644 --- a/src/hotload.c +++ b/src/hotload.c @@ -49,21 +49,18 @@ file_name(const char *file) } internal char * -resolve_symlink(char *file, enum watch_kind *kind) +resolve_symlink(char *file) { struct stat buffer; if (lstat(file, &buffer) != 0) { - *kind = WATCH_KIND_INVALID; return NULL; } if (S_ISDIR(buffer.st_mode)) { - *kind = WATCH_KIND_CATALOG; return copy_string(file); } if (!S_ISLNK(buffer.st_mode)) { - *kind = WATCH_KIND_FILE; return copy_string(file); } @@ -73,15 +70,32 @@ resolve_symlink(char *file, enum watch_kind *kind) if (read != -1) { result[read] = '\0'; - *kind = WATCH_KIND_FILE; return result; } free(result); - *kind = WATCH_KIND_INVALID; return NULL; } +internal enum watch_kind +resolve_watch_kind(char *file) +{ + struct stat buffer; + if (lstat(file, &buffer) != 0) { + return WATCH_KIND_INVALID; + } + + if (S_ISDIR(buffer.st_mode)) { + return WATCH_KIND_CATALOG; + } + + if (!S_ISLNK(buffer.st_mode)) { + return WATCH_KIND_FILE; + } + + return WATCH_KIND_INVALID; +} + internal char * same_catalog(char *absolutepath, struct watched_catalog *catalog_info) { @@ -148,8 +162,10 @@ bool hotloader_add_catalog(struct hotloader *hotloader, char *directory, char *e { if (hotloader->enabled) return false; - enum watch_kind kind; - char *real_path = resolve_symlink(directory, &kind); + char *real_path = resolve_symlink(directory); + if (!real_path) return false; + + enum watch_kind kind = resolve_watch_kind(real_path); if (kind != WATCH_KIND_CATALOG) return false; struct watched_entry entry = { @@ -170,8 +186,10 @@ bool hotloader_add_file(struct hotloader *hotloader, char *file) { if (hotloader->enabled) return false; - enum watch_kind kind; - char *real_path = resolve_symlink(file, &kind); + char *real_path = resolve_symlink(file); + if (!real_path) return false; + + enum watch_kind kind = resolve_watch_kind(real_path); if (kind != WATCH_KIND_FILE) return false; struct watched_entry entry = { |