diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs index 63b3b81212..4a8be6bce3 100644 --- a/src/main/frontend/config.cljs +++ b/src/main/frontend/config.cljs @@ -475,24 +475,22 @@ ([] (get-repo-config-path (state/get-current-repo))) ([repo] - (when repo - (get-file-path repo (str app-name "/" config-file))))) + (when-let [repo-dir (get-repo-dir repo)] + (fs2-path/path-join repo-dir app-name config-file)))) (defn get-custom-css-path ([] (get-custom-css-path (state/get-current-repo))) ([repo] - (when repo - (get-file-path repo - (str app-name "/" custom-css-file))))) + (when-let [repo-dir (get-repo-dir repo)] + (fs2-path/path-join repo-dir app-name custom-css-file)))) (defn get-export-css-path ([] (get-export-css-path (state/get-current-repo))) ([repo] - (when repo - (get-file-path repo - (str app-name "/" export-css-file))))) + (when-let [repo-dir (get-repo-dir repo)] + (fs2-path/path-join repo-dir app-name export-css-file)))) (defn expand-relative-assets-path ;; ../assets/xxx -> {assets|file}://{current-graph-root-path}/xxx @@ -514,9 +512,8 @@ ([] (get-custom-js-path (state/get-current-repo))) ([repo] - (when repo - (get-file-path repo - (str app-name "/" custom-js-file))))) + (when-let [repo-dir (get-repo-dir repo)] + (fs2-path/path-join repo-dir app-name custom-js-file)))) (defn get-block-hidden-properties [] diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index 0443ed304e..552533ef5f 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -12,7 +12,6 @@ [frontend.util :as util] [lambdaisland.glogi :as log] [promesa.core :as p] - [frontend.db :as db] [frontend.fs2.path :as fs2-path] [clojure.string :as string] [frontend.state :as state] @@ -51,16 +50,13 @@ (protocol/mkdir-recur! (get-fs dir) dir)) (defn readdir + "list all absolute paths in dir, absolute" [dir & {:keys [path-only?]}] (when-not path-only? - (js/console.error "BUG: (deprecation) path-only? always true") - ) + (js/console.error "BUG: (deprecation) path-only? is always true")) (p/let [result (protocol/readdir (get-fs dir) dir) result (bean/->clj result)] - (let [result (if (and path-only? (map? (first result))) - (map :path result) - result)] - (map gp-util/path-normalize result)))) + (map gp-util/path-normalize result))) (defn unlink! "Should move the path to logseq/recycle instead of deleting it." @@ -126,6 +122,7 @@ (protocol/rename! (get-fs old-path) repo old-path new-path))))) (defn copy! + "Only used by Logseq Sync" [repo old-path new-path] (cond (= old-path new-path) @@ -162,19 +159,18 @@ (defn open-dir [dir] (let [record (get-native-backend)] + (prn ::open-dir record) (p/let [result (protocol/open-dir record dir)] - (prn ::open-dir result) - (if (or (util/electron?) - (mobile-util/native-platform?)) + (prn ::open-dir-stage-1 result) + (when result (let [{:keys [path files]} result dir path _ (prn ::open-dir dir) files (mapv (fn [entry] (assoc entry :path (fs2-path/relative-path dir (:path entry)))) files)] - (prn :got files) - {:path dir :files files}) - result)))) + (prn :got-fixed files) + {:path dir :files files}))))) (defn get-files "List all files in the directory, recursively. diff --git a/src/main/frontend/fs/nfs.cljs b/src/main/frontend/fs/nfs.cljs index 240b506c6b..40bf1b6ea0 100644 --- a/src/main/frontend/fs/nfs.cljs +++ b/src/main/frontend/fs/nfs.cljs @@ -65,13 +65,10 @@ (defn check-directory-permission! [repo] - (js/console.error "check dir perm " repo) (when (config/local-db? repo) (p/let [repo-dir (config/get-repo-dir repo) - _ (prn (str "handle/" repo-dir)) handle-path (str "handle/" repo-dir) handle (idb/get-item handle-path)] - (prn ::check-perm handle) (when handle (add-nfs-file-handle! handle-path handle) (verify-permission repo true))))) @@ -96,7 +93,7 @@ (js/Promise. (fn [resolve reject] (let [timer (atom nil) timer' (js/setInterval (fn [] - (prn ::debug-checking-nfs-user-granted?) + (prn ::checking-nfs-permission) (when (state/nfs-user-granted? repo) (js/clearInterval @timer) (resolve true))) @@ -123,7 +120,8 @@ (let [handle-path (str "handle/" path)] ;; Same for all handles here, even for directories and ignored directories(for backing up) ;; FileSystemDirectoryHandle or FileSystemFileHandle - (add-nfs-file-handle! handle-path entry))))] + (when-not (string/includes? path "/.") + (add-nfs-file-handle! handle-path entry)))))] (->> files (remove (fn [file] (let [rpath (string/replace-first (.-webkitRelativePath file) (str root-dir "/") "") @@ -148,12 +146,12 @@ (let [handle-path (str "handle/" path)] ;; Same for all handles here, even for directories and ignored directories(for backing up) ;; FileSystemDirectoryHandle or FileSystemFileHandle - (add-nfs-file-handle! handle-path entry))))] + (when-not (string/includes? path "/.") + (add-nfs-file-handle! handle-path entry)))))] (p/all (->> files (remove (fn [file] (let [rpath (string/replace-first (.-webkitRelativePath file) (str root-dir "/") "") ext (util/get-file-ext rpath)] - (or (string/blank? rpath) (string/starts-with? rpath ".") (string/starts-with? rpath "logseq/bak") @@ -332,15 +330,15 @@ (let [handle-path (str "handle/" path)] ;; Same all handles here, even for directories and ignored directories(for backing up) ;; FileSystemDirectoryHandle or FileSystemFileHandle - (add-nfs-file-handle! handle-path entry)))) - _ (js/console.log "open-dir" files) + (when-not (string/includes? path "/.") + (add-nfs-file-handle! handle-path entry))))) dir-handle (first files) ;; FileSystemDirectoryHandle dir-name (.-name dir-handle) files (->> (next files) (remove (fn [file] - (let [rpath (string/replace-first (.-webkitRelativePath file) (str dir-name "/") "") + (let [rpath (.-webkitRelativePath file) ; + ; (string/replace-first (.-webkitRelativePath file) (str dir-name "/") "") ext (util/get-file-ext rpath)] - (or (string/blank? rpath) (string/starts-with? rpath ".") (string/starts-with? rpath "logseq/bak") @@ -353,7 +351,6 @@ ;; path content size mtime {:name (.-name file) :path (-> (.-webkitRelativePath file) - (string/replace-first (str dir-name "/") "") gp-util/path-normalize) :mtime (.-lastModified file) :size (.-size file) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 58c501f781..6fa4713c9e 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -8,7 +8,6 @@ [frontend.date :as date] [frontend.db :as db] [frontend.db.model :as db-model] - [frontend.db.model :as model] [frontend.db.utils :as db-utils] [frontend.db.query-dsl :as query-dsl] [frontend.diff :as diff] @@ -1500,7 +1499,7 @@ (when (and local? delete-local?) (when-let [href (if (util/electron?) href (second (re-find #"\((.+)\)$" full-text)))] - (let [block-file-rpath (model/get-block-file-path block) + (let [block-file-rpath (db-model/get-block-file-path block) asset-fpath (if (string/starts-with? href "assets://") (fs2-path/url-to-path href) (config/get-repo-fpath