Skip to content

Commit

Permalink
fix(android): apply url decode before fs watcher notifies
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed May 23, 2023
1 parent 1ce4697 commit 7f0457f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions android/app/src/main/java/com/logseq/app/FsWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,23 @@ public void onObserverEvent(int event, String path, SimpleFileMetadata metadata)
shouldRead = true;
}

URI dir = (new File(mPath)).toURI();
URI fpath = f.toURI();
Uri dir = Uri.fromFile(new File(mPath));
Uri fpath = Uri.fromFile(f);
String relpath = null;

if (fpath.getPath().startsWith(dir.getPath())) {
relpath = fpath.getPath().substring(dir.getPath().length());
if (relpath.startsWith("/")) {
relpath = relpath.substring(1);
}
relpath = Uri.decode(relpath);
} else {
Log.e("FsWatcher", "file path not under watch path");
return;
}


obj.put("path", Normalizer.normalize(dir.relativize(fpath).toString(), Normalizer.Form.NFC));
obj.put("path", Normalizer.normalize(relpath, Normalizer.Form.NFC));
obj.put("dir", Uri.fromFile(new File(mPath))); // Uri is for Android. URI is for RFC compatible
JSObject stat;

Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/fs/sync.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@
(when (sync-state--valid-to-accept-filewatcher-event? sync-state)
(when (or (:mtime stat) (= type "unlink"))
(go
(let [path (path-normalize (remove-dir-prefix dir path))
(let [path (path-normalize path)
files-meta (and (not= "unlink" type)
(<! (<get-local-files-meta
rsapi (:current-syncing-graph-uuid sync-state) dir [path])))
Expand Down

0 comments on commit 7f0457f

Please sign in to comment.