Skip to content

Commit

Permalink
Watching ignores hidden paths; Android watches sdcard;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed May 27, 2024
1 parent e2048f0 commit 2df61e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion etc/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ function lovr.threaderror(thread, err)
end

function lovr.filechanged(path, action, oldpath)
lovr.event.restart()
if not path:match('^%.') then
lovr.event.restart()
end
end

function lovr.log(message, level, tag)
Expand Down
18 changes: 11 additions & 7 deletions src/modules/filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct File {

static struct {
uint32_t ref;
bool watching;
dmon_watch_id watcher;
Archive* archives;
size_t savePathLength;
char savePath[1024];
Expand Down Expand Up @@ -191,7 +191,7 @@ void lovrFilesystemSetSource(const char* source) {
}

const char* lovrFilesystemGetSource(void) {
return state.source[0] ? state.source : NULL;
return state.source[0] ? state.source : NULL;
}

static void onFileEvent(dmon_watch_id id, dmon_action action, const char* dir, const char* path, const char* oldpath, void* ctx) {
Expand All @@ -213,18 +213,22 @@ static void onFileEvent(dmon_watch_id id, dmon_action action, const char* dir, c
}

void lovrFilesystemWatch(void) {
#ifdef ANDROID
const char* path = state.savePath;
#else
const char* path = state.source;
#endif
FileInfo info;
if (!state.watching && fs_stat(state.source, &info) && info.type == FILE_DIRECTORY) {
state.watching = true;
if (!state.watcher.id && fs_stat(path, &info) && info.type == FILE_DIRECTORY) {
dmon_init();
dmon_watch(state.source, onFileEvent, DMON_WATCHFLAGS_RECURSIVE, NULL);
state.watcher = dmon_watch(path, onFileEvent, DMON_WATCHFLAGS_RECURSIVE, NULL);
}
}

void lovrFilesystemUnwatch(void) {
if (state.watching) {
state.watching = false;
if (state.watcher.id) {
dmon_deinit();
state.watcher.id = 0;
}
}

Expand Down

0 comments on commit 2df61e9

Please sign in to comment.