fix: diff jumps when overwriting Zotero items

pull/2747/head
Tienson Qin 2021-08-31 18:44:20 +08:00
parent 81d971eff9
commit 7736fd96c8
5 changed files with 20 additions and 11 deletions

View File

@ -171,10 +171,10 @@
"Overwrite existing item page?"]
[:div
[:div.rounded-md.sm:max-w-xs
(ui/toggle (setting/setting :overwirte-mode?)
(fn [] (setting/set-setting! :overwirte-mode? (not (setting/setting :overwirte-mode?))))
(ui/toggle (setting/setting :overwrite-mode?)
(fn [] (setting/set-setting! :overwrite-mode? (not (setting/setting :overwrite-mode?))))
true)]]]
(when (setting/setting :overwirte-mode?)
(when (setting/setting :overwrite-mode?)
(ui/admonition
:warning
[:p.text-red-500

View File

@ -74,7 +74,7 @@
(let [{:keys [page-name properties abstract-note]} (extractor/extract item)]
(if (page-handler/page-exists? (str/lower-case page-name))
(if (setting/setting :overwirte-mode?)
(if (setting/setting :overwrite-mode?)
(page-handler/delete!
page-name
(fn [] (create-page page-name properties)))

View File

@ -10,7 +10,7 @@
:include-attachments? true
:attachments-block-text "[[Attachments]]"
:include-notes? true
:overwirte-mode? false
:overwrite-mode? false
:notes-block-text "[[Notes]]"
:zotero-data-directory ""
:zotero-linked-attachment-base-directory ""

View File

@ -173,7 +173,9 @@
(not (string/blank? db-content))
(not (:skip-compare? opts))
(not contents-matched?)
(not (contains? #{"excalidraw" "edn"} ext)))
(not (contains? #{"excalidraw" "edn"} ext))
(not (string/includes? path "/.recycle/"))
(zero? pending-writes))
(state/pub-event! [:file/not-matched-from-disk path local-content content])
(p/let [_ (verify-permission repo file-handle true)
_ (utils/writeFile file-handle content)

View File

@ -47,18 +47,25 @@
(error-handler error)
(log/error :write-file-failed error))))
(p/let [disk-content (-> (protocol/read-file this dir path nil)
(p/catch (fn [error] nil)))
(p/let [disk-content (when (not= stat :not-found)
(-> (protocol/read-file this dir path nil)
(p/catch (fn [error]
(js/console.error error)
nil))))
disk-content (or disk-content "")
ext (string/lower-case (util/get-file-ext path))
file-page (db/get-file-page-id path)
page-empty? (and file-page (db/page-empty? repo file-page))
db-content (or (db/get-file repo path) "")
contents-matched? (contents-matched? disk-content db-content)]
contents-matched? (contents-matched? disk-content db-content)
pending-writes (state/get-write-chan-length)]
(cond
(and
(not= stat :not-found) ; file on the disk was deleted
(not contents-matched?)
(not (contains? #{"excalidraw" "edn"} ext)))
(not (contains? #{"excalidraw" "edn"} ext))
(not (string/includes? path "/.recycle/"))
(zero? pending-writes))
(state/pub-event! [:file/not-matched-from-disk path disk-content content])
:else
@ -100,7 +107,7 @@
(let [path (concat-path dir path)]
(p/let [stat (p/catch
(protocol/stat this dir path)
(fn [_e] nil))
(fn [_e] :not-found))
sub-dir (first (util/get-dir-and-basename path))
_ (protocol/mkdir-recur! this sub-dir)]
(write-file-impl! this repo dir path content opts stat))))