Browse Source

fix: ignore changes in bak folder

Junyi Du 3 years ago
parent
commit
1fd160d9dd

+ 3 - 2
src/electron/electron/fs_watcher.cljs

@@ -3,7 +3,8 @@
             ["fs" :as fs]
             ["chokidar" :as watcher]
             [electron.utils :as utils]
-            ["electron" :refer [app]]))
+            ["electron" :refer [app]]
+            [frontend.util.fs :as util-fs]))
 
 ;; TODO: explore different solutions for different platforms
 ;; 1. https://github.com/Axosoft/nsfw
@@ -31,7 +32,7 @@
     (let [watcher (.watch watcher dir
                           (clj->js
                            {:ignored (fn [path]
-                                       (utils/ignored-path? dir path))
+                                       (util-fs/ignored-path? dir path))
                             :ignoreInitial false
                             :ignorePermissionErrors true
                             :interval polling-interval

+ 4 - 2
src/electron/electron/utils.cljs

@@ -42,14 +42,16 @@
                   (map #(path/join plugins-root (.-name %))))]
     dirs))
 
+;; keep same as ignored-path? in src/main/frontend/util/fs.cljs
+;; TODO: merge them
 (defn ignored-path?
   [dir path]
   (when (string? path)
     (or
      (some #(string/starts-with? path (str dir "/" %))
-           ["." ".recycle" "assets" "node_modules"])
+           ["." ".recycle" "assets" "node_modules" "logseq/bak"])
      (some #(string/includes? path (str "/" % "/"))
-           ["." ".recycle" "assets" "node_modules"])
+           ["." ".recycle" "assets" "node_modules" "logseq/bak"])
      (string/ends-with? path ".DS_Store")
      ;; hidden directory or file
      (let [relpath (path/relative dir path)]

+ 2 - 1
src/main/frontend/handler/web/nfs.cljs

@@ -16,6 +16,7 @@
             [frontend.search :as search]
             [frontend.state :as state]
             [frontend.util :as util]
+            [frontend.util.fs :as util-fs]
             [goog.object :as gobj]
             [lambdaisland.glogi :as log]
             [promesa.core :as p]
@@ -27,7 +28,7 @@
                         (let [path (:file/path f)]
                           (or (string/starts-with? path ".git/")
                               (string/includes? path ".git/")
-                              (and (util/ignored-path? "" path)
+                              (and (util-fs/ignored-path? "" path)
                                    (not= (:file/name f) ".gitignore")))))
                       files)]
     (if-let [ignore-file (some #(when (= (:file/name %) ".gitignore")

+ 0 - 17
src/main/frontend/util.cljc

@@ -1570,23 +1570,6 @@
    (defn meta-key-name []
      (if mac? "Cmd" "Ctrl")))
 
-;; TODO: share with electron
-(defn ignored-path?
-  [dir path]
-  (when (string? path)
-    (or
-     (some #(string/starts-with? path (str dir "/" %))
-           ["." ".recycle" "assets" "node_modules"])
-     (some #(string/includes? path (str "/" % "/"))
-           ["." ".recycle" "assets" "node_modules"])
-     ;; hidden directory or file
-     (re-find #"/\.[^.]+" path)
-     (re-find #"^\.[^.]+" path)
-     (let [path (string/lower-case path)]
-       (not
-        (some #(string/ends-with? path %)
-              [".md" ".markdown" ".org" ".edn" ".js" ".css" ".png" ".jpg" ".jpeg"]))))))
-
 (defn wrapped-by-quotes?
   [v]
   (and (string? v) (>= (count v) 2) (= "\"" (first v) (last v))))

+ 27 - 0
src/main/frontend/util/fs.cljs

@@ -0,0 +1,27 @@
+(ns frontend.util.fs
+  (:require [clojure.string :as string]
+            ["path" :as path]))
+
+;; TODO: move all file path related util functions to here
+
+;; keep same as ignored-path? in src/electron/electron/utils.cljs
+;; TODO: merge them
+(defn ignored-path?
+  [dir path]
+  (when (string? path)
+    (or
+     (some #(string/starts-with? path (str dir "/" %))
+           ["." ".recycle" "assets" "node_modules" "logseq/bak"])
+     (some #(string/includes? path (str "/" % "/"))
+           ["." ".recycle" "assets" "node_modules" "logseq/bak"])
+     (string/ends-with? path ".DS_Store")
+     ;; hidden directory or file
+     (let [relpath (path/relative dir path)]
+       (or (re-find #"/\.[^.]+" relpath)
+           (re-find #"^\.[^.]+" relpath)))
+     (let [path (string/lower-case path)]
+       (and
+        (not (string/blank? (path/extname path)))
+        (not
+         (some #(string/ends-with? path %)
+               [".md" ".markdown" ".org" ".js" ".edn" ".css"])))))))