fix: re-create the page when the file appears again

related to #5549
pull/5617/head
Tienson Qin 2022-06-07 12:17:36 +08:00
parent 09a9cda59c
commit 307f7bd755
3 changed files with 13 additions and 11 deletions

View File

@ -70,7 +70,7 @@
(p/let [result (ipc/ipc "writeFile" repo path content)
mtime (gobj/get result "mtime")]
(when-not contents-matched?
(ipc/ipc "backupDbFile" (config/get-local-dir repo) path db-content content))
(ipc/ipc "backupDbFile" (config/get-local-dir repo) path disk-content content))
(db/set-file-last-modified-at! repo path mtime)
(p/let [content (if (encrypt/encrypted-db? (state/get-current-repo))
(encrypt/decrypt content)

View File

@ -92,7 +92,7 @@
(db/file-exists? repo path))
(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))
(page-handler/delete! page-name #() :unlink-file? true))
(and (contains? #{"add" "change" "unlink"} type)
(string/ends-with? path "logseq/custom.css"))

View File

@ -160,19 +160,21 @@
page-name)))
(defn delete-file!
[repo page-name]
[repo page-name unlink-file?]
(let [file (db/get-page-file page-name)
file-path (:file/path file)]
;; delete file
(when-not (string/blank? file-path)
(db/transact! [[:db.fn/retractEntity [:file/path file-path]]])
(->
(p/let [_ (and (config/local-db? repo)
(mobile-util/native-platform?)
(fs/delete-file! repo file-path file-path {}))
_ (fs/unlink! repo (config/get-repo-path repo file-path) nil)])
(p/catch (fn [err]
(js/console.error "error: " err)))))))
(when unlink-file?
(->
(p/let [_ (and (config/local-db? repo)
(mobile-util/native-platform?)
;; TODO: @leizhe remove fs/delete-file! and use fs/unlink!
(fs/delete-file! repo file-path file-path {}))
_ (fs/unlink! repo (config/get-repo-path repo file-path) nil)])
(p/catch (fn [err]
(js/console.error "error: " err))))))))
(defn- compute-new-file-path
[old-path new-name]
@ -316,7 +318,7 @@
page (db/entity [:block/name page-name])]
(db/transact! tx-data)
(when delete-file? (delete-file! repo page-name))
(delete-file! repo page-name delete-file?)
;; if other page alias this pagename,
;; then just remove some attrs of this entity instead of retractEntity