fix: remove redundancy paths on db

This commit also removes the fragile files including page-metadata.edn
and metadata.edn.
This commit is contained in:
Tienson Qin
2022-11-07 13:29:15 +08:00
parent 7099158ee3
commit e56fb0fa53
11 changed files with 41 additions and 225 deletions

View File

@@ -1,6 +1,6 @@
(ns frontend.fs.capacitor-fs
"Implementation of fs protocol for mobile"
(:require ["@capacitor/filesystem" :refer [Encoding Filesystem Directory]]
(:require ["@capacitor/filesystem" :refer [Encoding Filesystem]]
[cljs-bean.core :as bean]
[clojure.string :as string]
[goog.string :as gstring]
@@ -227,20 +227,25 @@
(js/encodeURI %)
:else
(js/encodeURI (js/decodeURI %))))]
(js/encodeURI (js/decodeURI %))))
path' (cond
(and path (string/starts-with? path "file:/"))
(safe-encode-url path)
(cond (string/blank? path)
(safe-encode-url dir)
(string/blank? path)
(safe-encode-url dir)
(string/blank? dir)
(safe-encode-url path)
(string/blank? dir)
(safe-encode-url path)
(string/starts-with? path dir)
(safe-encode-url path)
(string/starts-with? path dir)
(safe-encode-url path)
:else
(let [path' (safe-encode-url path)]
(str dir "/" path')))))
:else
(let [path' (safe-encode-url path)]
(str dir "/" path')))
path' (string/replace path' "///private/" "///")]
path'))
(defn- local-container-path?
"Check whether `path' is logseq's container `localDocumentsPath' on iOS"

View File

@@ -7,15 +7,16 @@
[frontend.handler.editor :as editor]
[frontend.handler.file :as file-handler]
[frontend.handler.page :as page-handler]
[frontend.handler.repo :as repo-handler]
[frontend.handler.ui :as ui-handler]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.config :as gp-config]
[logseq.graph-parser.util.block-ref :as block-ref]
[frontend.mobile.util :as mobile-util]
[lambdaisland.glogi :as log]
[promesa.core :as p]
[frontend.state :as state]
[frontend.fs :as fs]))
[frontend.fs :as fs]
[frontend.fs.capacitor-fs :as capacitor-fs]))
;; all IPC paths must be normalized! (via gp-util/path-normalize)
@@ -49,10 +50,12 @@
[type {:keys [dir path content stat global-dir] :as payload}]
(when dir
(let [path (gp-util/path-normalize path)
path (if (mobile-util/native-platform?)
(capacitor-fs/normalize-file-protocol-path nil path)
path)
;; Global directory events don't know their originating repo so we rely
;; on the client to correctly identify it
repo (if global-dir (state/get-current-repo) (config/get-local-repo dir))
pages-metadata-path (config/get-pages-metadata-path)
{:keys [mtime]} stat
db-content (or (db/get-file repo path) "")]
(when (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
@@ -67,8 +70,7 @@
nil
(and (= "add" type)
(not= (string/trim content) (string/trim db-content))
(not= path pages-metadata-path))
(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?))
@@ -78,7 +80,6 @@
(and (= "change" type)
(not= (string/trim content) (string/trim db-content))
(not= path pages-metadata-path)
(not (gp-config/local-asset? (string/replace-first path dir ""))))
(when-not (and
(string/includes? path (str "/" (config/get-journals-directory) "/"))
@@ -103,19 +104,6 @@
(println "reloading custom.css")
(ui-handler/add-style-if-exists!))
;; When metadata is added to watcher, update timestamps in db accordingly
;; This event is not triggered on re-index
;; Persistent metadata is gold standard when db is offline, so it's forced
(and (contains? #{"add"} type)
(= path pages-metadata-path))
(p/do! (repo-handler/update-pages-metadata! repo content true))
;; Change is triggered by external changes, so update to the db
;; Don't forced update when db is online, but resolving conflicts
(and (contains? #{"change"} type)
(= path pages-metadata-path))
(p/do! (repo-handler/update-pages-metadata! repo content false))
(contains? #{"add" "change" "unlink"} type)
nil