Browse Source

fix(android): apply url decode before fs watcher notifies

Andelf 2 years ago
parent
commit
7f0457f23f

+ 16 - 3
android/app/src/main/java/com/logseq/app/FsWatcher.java

@@ -92,10 +92,23 @@ public class FsWatcher extends Plugin {
             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;
 

+ 1 - 1
src/main/frontend/fs/sync.cljs

@@ -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])))