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))))))
|
||||
|
||||
(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
|
||||
[p]
|
||||
|
@ -71,4 +71,4 @@
|
|||
[graph-dir]
|
||||
(->> (readdir 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))
|
||||
repo-dir (config/get-local-dir repo)
|
||||
{:keys [mtime]} stat
|
||||
db-content (db/get-file repo path)
|
||||
exists-in-db? (not (nil? db-content))
|
||||
db-content (or db-content "")]
|
||||
ext (keyword (path/file-ext path))]
|
||||
(when (contains? #{:org :md :markdown :css :js :edn :excalidraw :tldr} ext)
|
||||
(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))
|
||||
(cond
|
||||
(and (= "unlinkDir" type) dir)
|
||||
(state/pub-event! [:graph/dir-gone dir])
|
||||
(and (= "addDir" type) dir)
|
||||
(state/pub-event! [:graph/dir-back repo dir])
|
||||
|
||||
(and (= "addDir" type) dir)
|
||||
(state/pub-event! [:graph/dir-back repo dir])
|
||||
(contains? (:file/unlinked-dirs @state/state) dir)
|
||||
nil
|
||||
|
||||
(contains? (:file/unlinked-dirs @state/state) dir)
|
||||
nil
|
||||
(and (= "add" type)
|
||||
(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)
|
||||
(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 (= "change" type)
|
||||
(= dir repo-dir)
|
||||
(not= (string/trim content) (string/trim db-content))
|
||||
(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)
|
||||
(= dir repo-dir)
|
||||
(not= (string/trim content) (string/trim db-content))
|
||||
(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 (= "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))))
|
||||
(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
|
||||
(and (= "change" type)
|
||||
(= dir (global-config-handler/global-config-dir)))
|
||||
(when (= path "config.edn")
|
||||
(file-handler/alter-global-file
|
||||
(global-config-handler/global-config-path) content {:from-disk? true}))
|
||||
(and (= "change" type)
|
||||
(= dir (global-config-handler/global-config-dir)))
|
||||
(when (= path "config.edn")
|
||||
(file-handler/alter-global-file
|
||||
(global-config-handler/global-config-path) content {:from-disk? true}))
|
||||
|
||||
(and (= "change" type)
|
||||
(not exists-in-db?))
|
||||
(js/console.error "Can't get file in the db: " path)
|
||||
(and (= "change" type)
|
||||
(not exists-in-db?))
|
||||
(js/console.error "Can't get file in the db: " path)
|
||||
|
||||
(and (contains? #{"add" "change" "unlink"} type)
|
||||
(string/ends-with? path "logseq/custom.css"))
|
||||
(do
|
||||
(println "reloading custom.css")
|
||||
(ui-handler/add-style-if-exists!))
|
||||
(and (contains? #{"add" "change" "unlink"} type)
|
||||
(string/ends-with? path "logseq/custom.css"))
|
||||
(do
|
||||
(println "reloading custom.css")
|
||||
(ui-handler/add-style-if-exists!))
|
||||
|
||||
(contains? #{"add" "change" "unlink"} type)
|
||||
nil
|
||||
(contains? #{"add" "change" "unlink"} type)
|
||||
nil
|
||||
|
||||
:else
|
||||
(log/error :fs/watcher-no-handler {:type type
|
||||
:payload payload})))
|
||||
:else
|
||||
(log/error :fs/watcher-no-handler {:type type
|
||||
:payload payload})))))
|
||||
|
||||
;; return nil, otherwise the entire db will be transferred by ipc
|
||||
nil)))
|
||||
|
|
Loading…
Reference in New Issue