Просмотр исходного кода

fix(mobile): ignore bak and recycle in fs watcher (#4629)

* fix(ios): add ignore check to ios fs watcher
* fix(android): ignore bak directory in fs watcher
Andelf 3 лет назад
Родитель
Сommit
021ef03012

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

@@ -104,7 +104,7 @@ public class FsWatcher extends Plugin {
         File[] files = pathObj.listFiles();
         if (files != null) {
             for (int i = 0; i < files.length; ++i) {
-                if (files[i].isDirectory() && !files[i].getName().startsWith(".")) {
+                if (files[i].isDirectory() && !files[i].getName().startsWith(".") && !files[i].getName().equals("bak")) {
                     this.initialNotify(files[i], maxDepth - 1);
                 } else if (files[i].isFile()
                         && Pattern.matches("[^.].*?\\.(md|org|css|edn|text|markdown|yml|yaml|json|js)$",

+ 17 - 2
ios/App/App/FsWatcher.swift

@@ -171,14 +171,29 @@ public class PollingWatcher {
         
         if let enumerator = FileManager.default.enumerator(
             at: url,
-            includingPropertiesForKeys: [.isRegularFileKey],
+            includingPropertiesForKeys: [.isRegularFileKey, .nameKey, .isDirectoryKey],
             // NOTE: icloud downloading requires non-skipsHiddenFiles
             options: [.skipsPackageDescendants]) {
             
             var newMetaDb: [URL: SimpleFileMetadata] = [:]
             
             for case let fileURL as URL in enumerator {
-                if !fileURL.isSkipped() {
+                guard let resourceValues = try? fileURL.resourceValues(forKeys: [.isRegularFileKey, .nameKey, .isDirectoryKey]),
+                      let isDirectory = resourceValues.isDirectory,
+                      let isRegularFile = resourceValues.isRegularFile,
+                      let name = resourceValues.name
+                else {
+                    continue
+                }
+                
+                if isDirectory {
+                    // NOTE: URL.path won't end with a `/`
+                    if fileURL.path.hasSuffix("/logseq/bak") || name == ".recycle" || name.hasPrefix(".") || name == "node_modules" {
+                        enumerator.skipDescendants()
+                    }
+                }
+            
+                if isRegularFile && !fileURL.isSkipped() {
                     if let meta = SimpleFileMetadata(of: fileURL) {
                         newMetaDb[fileURL] = meta
                     }