Skip to content

Commit

Permalink
#19 - cleanup code for resolving symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Dec 12, 2017
1 parent 518927f commit 9253200
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/hotload.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ file_name(const char *file)
return name;
}

internal bool
resolve_symlink(char *file, char **real_path)
internal char *
resolve_symlink(char *file)
{
struct stat buffer;
if (lstat(file, &buffer) != 0) {
return false;
return NULL;
}

if (!S_ISLNK(buffer.st_mode)) {
*real_path = file;
return true;
return file;
}

ssize_t size = buffer.st_size + 1;
Expand All @@ -60,12 +59,11 @@ resolve_symlink(char *file, char **real_path)

if (read != -1) {
result[read] = '\0';
*real_path = result;
return true;
return result;
}

free(result);
return false;
return NULL;
}

internal struct watched_file *
Expand Down Expand Up @@ -109,16 +107,13 @@ internal FSEVENT_CALLBACK(hotloader_handler)
void hotloader_add_file(struct hotloader *hotloader, char *file)
{
if (!hotloader->enabled) {
char *real_path;
bool success = resolve_symlink(file, &real_path);

if (success) {
char *real_path = resolve_symlink(file);
if (real_path) {
struct watched_file watch_info;
watch_info.directory = file_directory(real_path);
watch_info.filename = file_name(real_path);

if (real_path != file) {
printf("hotload: symlink resolved, '%s' -> '%s'\n", file, real_path);
free(real_path);
}

Expand Down

0 comments on commit 9253200

Please sign in to comment.