mirror of https://github.com/logseq/logseq
fix: ignore binary files and other formats from watcher
parent
1861aa1697
commit
17f10edb39
|
@ -57,7 +57,7 @@
|
||||||
(re-find #"^\.[^.]+" relpath))))))
|
(re-find #"^\.[^.]+" relpath))))))
|
||||||
|
|
||||||
(def ^:private allowed-formats
|
(def ^:private allowed-formats
|
||||||
#{:org :markdown :md :edn :json :js :css :excalidraw :tldr})
|
#{:org :markdown :md :edn :json :js :css :excalidraw :tldr :pdf})
|
||||||
|
|
||||||
(defn- get-ext
|
(defn- get-ext
|
||||||
[p]
|
[p]
|
||||||
|
@ -71,4 +71,4 @@
|
||||||
[graph-dir]
|
[graph-dir]
|
||||||
(->> (readdir graph-dir)
|
(->> (readdir graph-dir)
|
||||||
(remove (partial ignored-path? graph-dir))
|
(remove (partial ignored-path? graph-dir))
|
||||||
(filter #(contains? allowed-formats (get-ext %)))))
|
(filter #(contains? allowed-formats (get-ext %)))))
|
||||||
|
|
|
@ -67,70 +67,71 @@
|
||||||
:else (config/get-local-repo dir))
|
:else (config/get-local-repo dir))
|
||||||
repo-dir (config/get-local-dir repo)
|
repo-dir (config/get-local-dir repo)
|
||||||
{:keys [mtime]} stat
|
{:keys [mtime]} stat
|
||||||
db-content (db/get-file repo path)
|
ext (keyword (path/file-ext path))]
|
||||||
exists-in-db? (not (nil? db-content))
|
(when (contains? #{:org :md :markdown :css :js :edn :excalidraw :tldr} ext)
|
||||||
db-content (or db-content "")]
|
(let [db-content (db/get-file repo path)
|
||||||
|
exists-in-db? (not (nil? db-content))
|
||||||
|
db-content (or db-content "")]
|
||||||
|
(when (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
|
||||||
|
(cond
|
||||||
|
(and (= "unlinkDir" type) dir)
|
||||||
|
(state/pub-event! [:graph/dir-gone dir])
|
||||||
|
|
||||||
(when (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
|
(and (= "addDir" type) dir)
|
||||||
(cond
|
(state/pub-event! [:graph/dir-back repo dir])
|
||||||
(and (= "unlinkDir" type) dir)
|
|
||||||
(state/pub-event! [:graph/dir-gone dir])
|
|
||||||
|
|
||||||
(and (= "addDir" type) dir)
|
(contains? (:file/unlinked-dirs @state/state) dir)
|
||||||
(state/pub-event! [:graph/dir-back repo dir])
|
nil
|
||||||
|
|
||||||
(contains? (:file/unlinked-dirs @state/state) dir)
|
(and (= "add" type)
|
||||||
nil
|
(not= (string/trim content) (string/trim db-content)))
|
||||||
|
(let [backup? (not (string/blank? db-content))]
|
||||||
|
(handle-add-and-change! repo path content db-content mtime backup?))
|
||||||
|
|
||||||
(and (= "add" type)
|
(and (= "change" type)
|
||||||
(not= (string/trim content) (string/trim db-content)))
|
(= dir repo-dir)
|
||||||
(let [backup? (not (string/blank? db-content))]
|
(not= (string/trim content) (string/trim db-content))
|
||||||
(handle-add-and-change! repo path content db-content mtime backup?))
|
(not (gp-config/local-asset? path)))
|
||||||
|
(when-not (and
|
||||||
|
(string/includes? path (str "/" (config/get-journals-directory) "/"))
|
||||||
|
(or
|
||||||
|
(= (string/trim content)
|
||||||
|
(string/trim (or (state/get-default-journal-template) "")))
|
||||||
|
(= (string/trim content) "-")
|
||||||
|
(= (string/trim content) "*")))
|
||||||
|
(handle-add-and-change! repo path content db-content mtime (not global-dir))) ;; no backup for global dir
|
||||||
|
|
||||||
(and (= "change" type)
|
(and (= "unlink" type)
|
||||||
(= dir repo-dir)
|
exists-in-db?)
|
||||||
(not= (string/trim content) (string/trim db-content))
|
(p/let [dir-exists? (fs/file-exists? dir "")]
|
||||||
(not (gp-config/local-asset? path)))
|
(when dir-exists?
|
||||||
(when-not (and
|
(when-let [page-name (db/get-file-page path)]
|
||||||
(string/includes? path (str "/" (config/get-journals-directory) "/"))
|
(println "Delete page: " page-name ", file path: " path ".")
|
||||||
(or
|
(page-handler/delete! page-name #() :delete-file? false))))
|
||||||
(= (string/trim content)
|
|
||||||
(string/trim (or (state/get-default-journal-template) "")))
|
|
||||||
(= (string/trim content) "-")
|
|
||||||
(= (string/trim content) "*")))
|
|
||||||
(handle-add-and-change! repo path content db-content mtime (not global-dir))) ;; no backup for global dir
|
|
||||||
|
|
||||||
(and (= "unlink" type)
|
|
||||||
exists-in-db?)
|
|
||||||
(p/let [dir-exists? (fs/file-exists? dir "")]
|
|
||||||
(when dir-exists?
|
|
||||||
(when-let [page-name (db/get-file-page path)]
|
|
||||||
(println "Delete page: " page-name ", file path: " path ".")
|
|
||||||
(page-handler/delete! page-name #() :delete-file? false))))
|
|
||||||
|
|
||||||
;; global config handling
|
;; global config handling
|
||||||
(and (= "change" type)
|
(and (= "change" type)
|
||||||
(= dir (global-config-handler/global-config-dir)))
|
(= dir (global-config-handler/global-config-dir)))
|
||||||
(when (= path "config.edn")
|
(when (= path "config.edn")
|
||||||
(file-handler/alter-global-file
|
(file-handler/alter-global-file
|
||||||
(global-config-handler/global-config-path) content {:from-disk? true}))
|
(global-config-handler/global-config-path) content {:from-disk? true}))
|
||||||
|
|
||||||
(and (= "change" type)
|
(and (= "change" type)
|
||||||
(not exists-in-db?))
|
(not exists-in-db?))
|
||||||
(js/console.error "Can't get file in the db: " path)
|
(js/console.error "Can't get file in the db: " path)
|
||||||
|
|
||||||
(and (contains? #{"add" "change" "unlink"} type)
|
(and (contains? #{"add" "change" "unlink"} type)
|
||||||
(string/ends-with? path "logseq/custom.css"))
|
(string/ends-with? path "logseq/custom.css"))
|
||||||
(do
|
(do
|
||||||
(println "reloading custom.css")
|
(println "reloading custom.css")
|
||||||
(ui-handler/add-style-if-exists!))
|
(ui-handler/add-style-if-exists!))
|
||||||
|
|
||||||
(contains? #{"add" "change" "unlink"} type)
|
(contains? #{"add" "change" "unlink"} type)
|
||||||
nil
|
nil
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(log/error :fs/watcher-no-handler {:type type
|
(log/error :fs/watcher-no-handler {:type type
|
||||||
:payload payload})))
|
:payload payload})))))
|
||||||
|
|
||||||
;; return nil, otherwise the entire db will be transferred by ipc
|
;; return nil, otherwise the entire db will be transferred by ipc
|
||||||
nil)))
|
nil)))
|
||||||
|
|
Loading…
Reference in New Issue