fix(ios): remove private part from file watcher events

pull/7184/head
Tienson Qin 2022-11-07 20:44:58 +08:00
parent 222ce20946
commit 02dfb9ede5
3 changed files with 22 additions and 13 deletions

View File

@ -212,6 +212,11 @@
(error-handler error)
(log/error :write-file-failed error)))))))))
(defn remove-private-part
"iOS sometimes return the private part."
[path]
(string/replace path "///private/" "///"))
(defn normalize-file-protocol-path [dir path]
(let [dir (some-> dir (string/replace #"/+$" ""))
dir (if (and (not-empty dir) (string/starts-with? dir "/"))
@ -243,9 +248,8 @@
:else
(let [path' (safe-encode-url path)]
(str dir "/" path')))
path' (string/replace path' "///private/" "///")]
path'))
(str dir "/" path')))]
(remove-private-part path)))
(defn- local-container-path?
"Check whether `path' is logseq's container `localDocumentsPath' on iOS"

View File

@ -323,15 +323,20 @@
(-relative-path [this]))
(defn relative-path [o]
(cond
(implements? IRelativePath o)
(-relative-path o)
(let [repo-dir (config/get-repo-dir (state/get-current-repo))]
(cond
(implements? IRelativePath o)
(-relative-path o)
(string? o)
(remove-user-graph-uuid-prefix o)
;; full path
(and (string? o) (string/starts-with? o repo-dir))
(string/replace o (str repo-dir "/") "")
:else
(throw (js/Error. (str "unsupport type " (str o))))))
(string? o)
(remove-user-graph-uuid-prefix o)
:else
(throw (js/Error. (str "unsupport type " (str o)))))))
(defprotocol IChecksum
(-checksum [this]))
@ -473,8 +478,7 @@
(state/pub-event! [:ui/notify-skipped-downloading-files
(map -relative-path reserved-files)])
(prn "Skipped downloading those file paths with reserved chars: "
(map -relative-path reserved-files))
)
(map -relative-path reserved-files)))
(remove
#(fs-util/include-reserved-chars? (-relative-path %))
files)))

View File

@ -569,7 +569,8 @@
(defmethod handle :file-watcher/changed [[_ ^js event]]
(let [type (.-event event)
payload (-> event
(js->clj :keywordize-keys true))]
(js->clj :keywordize-keys true)
(update :path capacitor-fs/remove-private-part))]
(fs-watcher/handle-changed! type payload)
(when (file-sync-handler/enable-sync?)
(sync/file-watch-handler type payload))))