浏览代码

refactor(fs): mv fs2 logic to logseq.common pkg

Andelf 2 年之前
父节点
当前提交
3c0973013b

+ 1 - 0
deps.edn

@@ -27,6 +27,7 @@
   camel-snake-kebab/camel-snake-kebab   {:mvn/version "0.4.2"}
   instaparse/instaparse                 {:mvn/version "1.4.10"}
   org.clojars.mmb90/cljs-cache          {:mvn/version "0.1.4"}
+  logseq/common                         {:local/root "deps/common"}
   logseq/graph-parser                   {:local/root "deps/graph-parser"}
   metosin/malli                         {:mvn/version "0.10.0"}
   fipp/fipp                             {:mvn/version "0.6.26"}}

+ 7 - 0
deps/common/deps.edn

@@ -0,0 +1,7 @@
+{:deps
+ ;; External deps should be kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
+ {datascript/datascript {:mvn/version "1.3.8"}}
+ :aliases
+ {:clj-kondo
+  {:replace-deps {clj-kondo/clj-kondo {:mvn/version "2022.12.08"}}
+   :main-opts  ["-m" "clj-kondo.main"]}}}

+ 13 - 8
src/main/frontend/fs2/path.cljs → deps/common/src/logseq/common/path.cljs

@@ -1,4 +1,4 @@
-(ns frontend.fs2.path
+(ns logseq.common.path
   "Path manipulation functions, use '/' on all platforms.
    Also handles URL paths."
   (:require [clojure.string :as string]
@@ -10,15 +10,14 @@
   (and (string? s)
        (or (string/starts-with? s "file://") ;; mobile platform
            (string/starts-with? s "content://") ;; android only
-           (string/starts-with? s "assets://") ;; FIXME: Electron asset, not urlencoded
+           (string/starts-with? s "assets://") ;; Electron asset, urlencoded
            (string/starts-with? s "logseq://") ;; reserved for future fs protocl
            (string/starts-with? s "memory://") ;; special memory fs
            (string/starts-with? s "s3://"))))
 
-
 (defn filename
   "File name of a path or URL.
-   Returns nil when it's a path."
+   Returns nil when it's a directory."
   [path]
   (let [fname (if (string/ends-with? path "/")
                 nil
@@ -27,7 +26,6 @@
       (gp-util/safe-decode-uri-component fname)
       fname)))
 
-
 (defn split-ext
   "Split file name into stem and extension, for both path and URL"
   [path]
@@ -154,7 +152,7 @@
   "Join path segments, or URL base and path segments"
   [base & segments]
 
-  (cond 
+  (cond
     (nil? base)
     (println "path join global directory" segments)
     (= base "")
@@ -245,7 +243,6 @@
           (str base-prefix (string/join "/" remain-segs)))))))
 
 
-
 (defn parent
   "Parent, containing directory"
   [path]
@@ -255,7 +252,6 @@
     nil))
 
 
-
 (defn resolve-relative-path
   "Assume current-path is a file"
   [current-path rel-path]
@@ -285,3 +281,12 @@
       (gp-util/safe-decode-uri-component (str base-prefix (string/join "/" remain-segs)))
       (str base-prefix (string/join "/" remain-segs)))))
 
+;; compat
+(defn basename
+  [path]
+  (let [path (string/replace path #"/$" "")]
+    (filename path)))
+
+(defn dirname
+  [path]
+  (parent path))

+ 34 - 0
deps/common/src/logseq/common/path_test.cljs

@@ -0,0 +1,34 @@
+(ns logseq.common.path-test
+  (:require [cljs.test :refer [deftest is testing]]
+            [logseq.common.path :as path]))
+
+
+
+(deftest test-safe-file-name?
+  (testing "safe-file-name"
+    (is (path/safe-filename? "foo"))
+    (is (path/safe-filename? "foo bar"))
+    (is (path/safe-filename? "foo-bar"))
+    (is (path/safe-filename? "foo_bar"))
+    (is (path/safe-filename? "foo.bar"))
+    (is (path/safe-filename? "foo..bar"))
+    (is (path/safe-filename? "foo...bar"))
+    (is (= nil (path/safe-filename? "foo/bar")))
+    (is (not (path/safe-filename? "foo?bar")))
+    (is (not (path/safe-filename? "foo<bar")))
+    (is (not (path/safe-filename? "foo>bar")))))
+
+
+(deftest path-join
+  (testing "join-path")
+  (is (= "foo/bar" (path/path-join "foo" "bar")))
+  (is (= "foo/bar" (path/path-join "foo/" "bar")))
+  (is (= "/foo/bar/baz/asdf" (path/path-join "/foo/bar//baz/asdf/quux/..")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar" "baz")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar/" "baz")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar/" "/baz")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar" "/baz")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar" "/baz/")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar/" "/baz/")))
+  (is (= "https://foo.bar/baz" (path/path-join "https://foo.bar/" "/baz"))))
+

+ 2 - 2
src/main/electron/listener.cljs

@@ -10,7 +10,6 @@
             [frontend.db.model :as db-model]
             [frontend.fs.sync :as sync]
             [frontend.fs.watcher-handler :as watcher-handler]
-            [frontend.fs2.path :as fs2-path]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.file-sync :as file-sync-handler]
             [frontend.handler.notification :as notification]
@@ -20,6 +19,7 @@
             [frontend.handler.user :as user]
             [frontend.state :as state]
             [frontend.ui :as ui]
+            [logseq.common.path :as path]
             [logseq.graph-parser.util :as gp-util]
             [promesa.core :as p]))
 
@@ -53,7 +53,7 @@
                        (let [{:keys [type payload]} (bean/->clj data)
                              path (gp-util/path-normalize (:path payload))
                              dir (:dir payload)
-                             payload (assoc payload :path (fs2-path/relative-path dir path))]
+                             payload (assoc payload :path (path/relative-path dir path))]
                          (watcher-handler/handle-changed! type payload)
                          (when (file-sync-handler/enable-sync?)
                            (sync/file-watch-handler type payload)))))

+ 3 - 3
src/main/frontend/components/block.cljs

@@ -82,7 +82,7 @@
             [rum.core :as rum]
             [shadow.loader :as loader]
             [datascript.impl.entity :as e]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 (defn safe-read-string
   ([s]
@@ -200,7 +200,7 @@
                     (if (and (gp-config/local-protocol-asset? src)
                              (file-sync/current-graph-sync-on?))
                       (let [*exist? (::exist? state)
-                            asset-path (fs2-path/url-to-path src)]
+                            asset-path (path/url-to-path src)]
                         (if (string/blank? asset-path)
                           (reset! *exist? false)
                           ;; FIXME(andelf): possible bug here
@@ -397,7 +397,7 @@
                        (when (mobile-util/native-platform?)
                          ;; File URL must be legal, so filename muse be URI-encoded
                          (let [[rel-dir basename] (util/get-dir-and-basename href)
-                               asset-url (fs2-path/path-join repo-dir rel-dir basename)]
+                               asset-url (path/path-join repo-dir rel-dir basename)]
                            (.share Share (clj->js {:url asset-url
                                                    :title "Open file with your favorite app"})))))]
 

+ 2 - 3
src/main/frontend/components/sidebar.cljs

@@ -37,11 +37,10 @@
             [frontend.util.cursor :as cursor]
             [goog.dom :as gdom]
             [goog.object :as gobj]
-            [logseq.graph-parser.util :as gp-util]
             [react-draggable]
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 (rum/defc nav-content-item < rum/reactive
   [name {:keys [class]} child]
@@ -564,7 +563,7 @@
         width (js/Math.round (* (.toFixed (/ finished total) 2) 100))
         display-filename (some-> (:current-parsing-file state)
                                  not-empty
-                                 fs2-path/filename)
+                                 path/filename)
         left-label [:div.flex.flex-row.font-bold
                     (t :parsing-files)
                     [:div.hidden.md:flex.flex-row

+ 12 - 13
src/main/frontend/config.cljs

@@ -2,10 +2,10 @@
   "App config and fns built on top of configuration"
   (:require [clojure.set :as set]
             [clojure.string :as string]
-            [frontend.fs2.path :as fs2-path]
             [frontend.mobile.util :as mobile-util]
             [frontend.state :as state]
             [frontend.util :as util]
+            [logseq.common.path :as path]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.util :as gp-util]
             [shadow.resource :as rc]))
@@ -420,7 +420,7 @@
   [repo-url path]
   (if (and (or (util/electron?) (mobile-util/native-platform?))
            (local-db? repo-url))
-    (fs2-path/path-join (get-repo-dir repo-url) path)
+    (path/path-join (get-repo-dir repo-url) path)
     (util/node-path.join (get-repo-dir repo-url) path)))
 
 (defn get-file-path
@@ -431,7 +431,7 @@
     (let [path (cond
                  (demo-graph?)
                  (let [dir (get-repo-dir repo-url)
-                       r (fs2-path/path-join dir rpath)]
+                       r (path/path-join dir rpath)]
                    (js/console.error "get-file-path" r)
                    r)
 
@@ -444,7 +444,7 @@
 
                  (and (mobile-util/native-ios?) (local-db? repo-url))
                  (let [dir (get-repo-dir repo-url)]
-                   (fs2-path/path-join dir rpath))
+                   (path/path-join dir rpath))
 
                  (and (mobile-util/native-android?) (local-db? repo-url))
                  (let [dir (get-repo-dir repo-url)
@@ -475,33 +475,32 @@
    (get-repo-config-path (state/get-current-repo)))
   ([repo]
    (when-let [repo-dir (get-repo-dir repo)]
-     (fs2-path/path-join repo-dir app-name config-file))))
+     (path/path-join repo-dir app-name config-file))))
 
 (defn get-custom-css-path
   ([]
    (get-custom-css-path (state/get-current-repo)))
   ([repo]
    (when-let [repo-dir (get-repo-dir repo)]
-     (fs2-path/path-join repo-dir app-name custom-css-file))))
+     (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-let [repo-dir (get-repo-dir repo)]
-     (fs2-path/path-join repo-dir app-name  export-css-file))))
+     (path/path-join repo-dir app-name  export-css-file))))
 
 (defn expand-relative-assets-path
-  ;; resolve all relative links in custom.css to assets:// URL
+  "Resolve all relative links in custom.css to assets:// URL"
   ;; ../assets/xxx -> {assets|file}://{current-graph-root-path}/xxx
   [source]
-  (prn ::expand-relative-assets-path source)
   (let [protocol (and (string? source)
                       (not (string/blank? source))
                       (if (util/electron?) "assets://" "file://"))
-             ;; BUG: use "assets" as fake current directory
+        ;; BUG: use "assets" as fake current directory
         assets-link-fn (fn [_]
-                        (str (fs2-path/path-join protocol
+                        (str (path/path-join protocol
                                                  (get-repo-dir (state/get-current-repo)) "assets"))
                         "/")]
     (when (not-empty source)
@@ -512,14 +511,14 @@
   []
   (when-let [repo-dir (and (local-db? (state/get-current-repo))
                             (get-repo-dir (state/get-current-repo)))]
-    (fs2-path/path-join repo-dir "assets")))
+    (path/path-join repo-dir "assets")))
 
 (defn get-custom-js-path
   ([]
    (get-custom-js-path (state/get-current-repo)))
   ([repo]
    (when-let [repo-dir (get-repo-dir repo)]
-     (fs2-path/path-join repo-dir app-name custom-js-file))))
+     (path/path-join repo-dir app-name custom-js-file))))
 
 (defn get-block-hidden-properties
   []

+ 0 - 1
src/main/frontend/db/conn.cljs

@@ -8,7 +8,6 @@
             [frontend.util.text :as text-util]
             [logseq.graph-parser.text :as text]
             [logseq.db :as ldb]
-            [frontend.fs2.path :as fs2-path]
             [logseq.graph-parser.util :as gp-util]))
 
 (defonce conns (atom {}))

+ 1 - 2
src/main/frontend/db/model.cljs

@@ -6,7 +6,6 @@
             [clojure.string :as string]
             [clojure.walk :as walk]
             [datascript.core :as d]
-            [frontend.config :as config]
             [frontend.date :as date]
             [frontend.db.conn :as conn]
             [frontend.db.react :as react]
@@ -263,7 +262,7 @@
    (get-file (state/get-current-repo) path))
   ([repo path]
    (when (string/starts-with? path "/")
-     (js/console.error "BUG: Using absolute path while querying DB"))
+     (js/console.error "BUG: Using absolute path while querying DB" path))
    (when (and repo path)
      (when-let [db (conn/get-db repo)]
        (:file/content (db-utils/entity db [:file/path path]))))))

+ 5 - 5
src/main/frontend/fs.cljs

@@ -12,7 +12,7 @@
             [frontend.util :as util]
             [lambdaisland.glogi :as log]
             [promesa.core :as p]
-            [frontend.fs2.path :as fs2-path]
+            [logseq.common.path :as path]
             [clojure.string :as string]
             [frontend.state :as state]
             [logseq.graph-parser.util :as gp-util]
@@ -157,7 +157,7 @@
   ([fpath]
    (protocol/stat (get-fs fpath) fpath))
   ([dir path]
-   (let [fpath (fs2-path/path-join dir path)]
+   (let [fpath (path/path-join dir path)]
      (protocol/stat (get-fs dir) fpath))))
 
 (defn open-dir
@@ -171,7 +171,7 @@
               dir path
               _ (prn ::open-dir dir)
               files (mapv (fn [entry]
-                            (assoc entry :path (fs2-path/relative-path dir (:path entry))))
+                            (assoc entry :path (path/relative-path dir (:path entry))))
                           files)]
           (prn :got-fixed files)
           {:path dir :files files})))))
@@ -190,7 +190,7 @@
               _ (prn ::prepare-rel-path dir)
               files (mapv (fn [entry]
                             ;; (prn ::xx entry)
-                            (assoc entry :path (fs2-path/relative-path dir (:path entry))))
+                            (assoc entry :path (path/relative-path dir (:path entry))))
                           files)]
           (prn :got files)
           {:path dir :files files})
@@ -242,7 +242,7 @@
   "href is from `make-asset-url`, so it's most likely a full-path"
   [href]
   (p/let [repo-dir (config/get-repo-dir (state/get-current-repo))
-          rpath (fs2-path/relative-path repo-dir href)
+          rpath (path/relative-path repo-dir href)
           exist? (file-exists? repo-dir rpath)]
     (prn ::href-exists href exist?)
     exist?))

+ 17 - 39
src/main/frontend/fs/capacitor_fs.cljs

@@ -13,8 +13,7 @@
             [lambdaisland.glogi :as log]
             [promesa.core :as p]
             [rum.core :as rum]
-            [logseq.graph-parser.util :as gp-util]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 (when (mobile-util/native-ios?)
   (defn ios-ensure-documents!
@@ -31,22 +30,9 @@
         (p/do!
          (.requestPermissions Filesystem))))))
 
-
-;; FIXME: should distinguish between no-exist and error
-(defn- <file-exists?
-  [fpath]
-  (p/catch (p/let [fpath (fs2-path/path-normalize fpath)
-                   stat (.stat Filesystem (clj->js {:path fpath}))]
-             (-> stat
-                 bean/->clj
-                 :type
-                 (= "file")))
-           (fn [_error]
-             false)))
-
 (defn- <dir-exists?
   [fpath]
-  (p/catch (p/let [fpath (fs2-path/path-normalize fpath)
+  (p/catch (p/let [fpath (path/path-normalize fpath)
                    stat (.stat Filesystem (clj->js {:path fpath}))]
              (-> stat
                  bean/->clj
@@ -80,19 +66,12 @@
 
 (defn- <readdir [path]
   (-> (p/chain (.readdir Filesystem (clj->js {:path path}))
-               #(js->clj % :keywordize-keys true)
-               :files)
+              #(js->clj % :keywordize-keys true)
+              :files)
       (p/catch (fn [error]
                  (js/console.error "readdir Error: " path ": " error)
                  nil))))
 
-(defn- <stat [path]
-  (-> (p/chain (.stat Filesystem (clj->js {:path path}))
-               #(js->clj % :keywordize-keys true))
-      (p/catch (fn [error]
-                 (js/console.error "stat Error: " path ": " error)
-                 nil))))
-
 (defn- get-file-paths
   "get all file paths recursively"
   [path]
@@ -221,7 +200,7 @@
 
 (defn- write-file-impl!
   [repo dir rpath content {:keys [ok-handler error-handler old-content skip-compare?]} stat]
-  (let [fpath (fs2-path/path-join dir rpath)]
+  (let [fpath (path/path-join dir rpath)]
     (if (or (string/blank? repo) skip-compare?)
       (p/catch
        (p/let [result (<write-file-with-utf8 fpath content)]
@@ -356,16 +335,16 @@
                    (log/error :mkdir-recur! {:path dir
                                              :error error})))))
   (readdir [_this dir]                  ; recursive
-    (let [dir (fs2-path/path-normalize dir)]
+    (let [dir (path/path-normalize dir)]
       (get-file-paths dir)))
   (unlink! [this repo fpath _opts]
     (p/let [_ (prn ::unlink fpath)
             repo-dir (config/get-local-dir repo)
-            recycle-dir (fs2-path/path-join repo-dir config/app-name ".recycle") ;; logseq/.recycle
+            recycle-dir (path/path-join repo-dir config/app-name ".recycle") ;; logseq/.recycle
             ;; convert url to pure path
-            file-name (-> (fs2-path/trim-dir-prefix repo-dir fpath)
+            file-name (-> (path/trim-dir-prefix repo-dir fpath)
                           (string/replace "/" "_"))
-            new-path (fs2-path/path-join recycle-dir file-name)
+            new-path (path/path-join recycle-dir file-name)
             _ (protocol/mkdir-recur! this recycle-dir)]
       (protocol/rename! this repo fpath new-path)))
   (rmdir! [_this _dir]
@@ -373,27 +352,26 @@
     nil)
   (read-file [_this dir path _options]
     (prn ::read-file dir path)
-    (let [fpath (fs2-path/path-join dir path)]
+    (let [fpath (path/path-join dir path)]
       (->
        (<read-file-with-utf8 fpath)
        (p/catch (fn [error]
                   (log/error :read-file-failed error))))))
   (write-file! [_this repo dir path content opts]
     (prn ::write-file dir path)
-    (let [fpath (fs2-path/path-join dir path)]
+    (let [fpath (path/path-join dir path)]
       (p/let [stat (p/catch
                     (.stat Filesystem (clj->js {:path fpath}))
                     (fn [_e] :not-found))]
         ;; `path` is full-path
         (write-file-impl! repo dir path content opts stat))))
   (rename! [_this _repo old-path new-path]
-    (p/catch
-     (p/let [_ (.rename Filesystem
-                        (clj->js
-                         {:from old-path
-                          :to new-path}))])
-     (fn [error]
-       (log/error :rename-file-failed error))))
+    (-> (.rename Filesystem
+                 (clj->js
+                  {:from old-path
+                   :to new-path}))
+        (p/catch (fn [error]
+                   (log/error :rename-file-failed error)))))
   (copy! [_this _repo old-path new-path]
     (-> (.copy Filesystem
                (clj->js

+ 13 - 13
src/main/frontend/fs/memory_fs.cljs

@@ -5,7 +5,7 @@
   (:require [cljs-bean.core :as bean]
             [frontend.db :as db]
             [frontend.fs.protocol :as protocol]
-            [frontend.fs2.path :as fs2-path]
+            [logseq.common.path :as path]
             [promesa.core :as p]))
 
 (defn- <readdir
@@ -27,7 +27,7 @@
                                            (-> (js/window.pfs.readdir dir)
                                                (p/then bean/->clj)
                                                (p/then (fn [rpaths]
-                                                         (mapv #(fs2-path/path-join dir %) rpaths)))))]
+                                                         (mapv #(path/path-join dir %) rpaths)))))]
                        (p/recur result (concat (rest dirs) dir-content)))))]
     result))
 
@@ -50,43 +50,43 @@
   protocol/Fs
   (mkdir! [_this dir]
     (when js/window.pfs
-      (let [fpath (fs2-path/url-to-path dir)]
+      (let [fpath (path/url-to-path dir)]
         (-> (js/window.pfs.mkdir fpath)
             (p/catch (fn [error] (println "Mkdir error: " error)))))))
   (readdir [_this dir]
     (when js/window.pfs
-      (let [fpath (fs2-path/url-to-path dir)]
+      (let [fpath (path/url-to-path dir)]
         (-> (<readdir fpath)
             (p/then (fn [rpaths]
                       (prn ::debug rpaths)
-                      (mapv #(fs2-path/path-join "memory://" %) rpaths)))))))
+                      (mapv #(path/path-join "memory://" %) rpaths)))))))
 
   (unlink! [_this _repo path opts]
     (when js/window.pfs
-      (p/let [fpath (fs2-path/url-to-path path)
+      (p/let [fpath (path/url-to-path path)
               stat (js/window.pfs.stat fpath)]
         (if (= (.-type stat) "file")
           (js/window.pfs.unlink fpath opts)
           (p/rejected "Unlinking a directory is not allowed, use rmdir! instead")))))
   (rmdir! [_this dir]
-    (let [fpath (fs2-path/url-to-path dir)]
+    (let [fpath (path/url-to-path dir)]
       (js/window.workerThread.rimraf fpath)))
   (read-file [_this dir path options]
-    (let [fpath (fs2-path/url-to-path (fs2-path/path-join dir path))]
+    (let [fpath (path/url-to-path (path/path-join dir path))]
       (js/window.pfs.readFile fpath (clj->js options))))
   (write-file! [_this repo dir rpath content _opts]
-    (p/let [fpath (fs2-path/url-to-path (fs2-path/path-join dir rpath))
-            containing-dir (fs2-path/parent fpath)
+    (p/let [fpath (path/url-to-path (path/path-join dir rpath))
+            containing-dir (path/parent fpath)
             _ (<ensure-dir! containing-dir)
             _ (js/window.pfs.writeFile fpath content)]
       (db/set-file-content! repo rpath content)
       (db/set-file-last-modified-at! repo rpath (js/Date.))))
   (rename! [_this _repo old-path new-path]
-    (let [old-path (fs2-path/url-to-path old-path)
-          new-path (fs2-path/url-to-path new-path)]
+    (let [old-path (path/url-to-path old-path)
+          new-path (path/url-to-path new-path)]
       (js/window.pfs.rename old-path new-path)))
   (stat [_this fpath]
-    (let [fpath (fs2-path/url-to-path fpath)]
+    (let [fpath (path/url-to-path fpath)]
       (js/window.pfs.stat fpath)))
   
   (open-dir [_this _dir]

+ 16 - 15
src/main/frontend/fs/nfs.cljs

@@ -18,7 +18,7 @@
             [frontend.handler.notification :as notification]
             ["/frontend/utils" :as utils]
             [logseq.graph-parser.util :as gp-util]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 ;; Cache the file handles in the memory so that
 ;; the browser will not keep asking permissions.
@@ -173,15 +173,15 @@
 (defrecord ^:large-vars/cleanup-todo Nfs []
   protocol/Fs
   (mkdir! [_this dir]
-    (let [dir (fs2-path/path-normalize dir)
-          parent-dir (fs2-path/parent dir)
+    (let [dir (path/path-normalize dir)
+          parent-dir (path/parent dir)
 
           parent-handle-path (str "handle/" parent-dir)]
       (-> (p/let [parent-handle (or (get-nfs-file-handle parent-handle-path)
                                     (idb/get-item parent-handle-path))
                   _ (when parent-handle (verify-handle-permission parent-handle true))]
             (when parent-handle
-              (p/let [new-dir-name (fs2-path/filename dir)
+              (p/let [new-dir-name (path/filename dir)
                       new-handle (.getDirectoryHandle ^js parent-handle new-dir-name
                                                       #js {:create true})
                       handle-path (str "handle/" dir)
@@ -209,9 +209,9 @@
 
   (unlink! [this repo fpath _opts]
     (let [repo-dir (config/get-repo-dir repo)
-          filename (fs2-path/filename fpath)
+          filename (path/filename fpath)
           handle-path (str "handle/" fpath)
-          recycle-dir (fs2-path/path-join repo-dir config/app-name config/recycle-dir)]
+          recycle-dir (path/path-join repo-dir config/app-name config/recycle-dir)]
       (->
        (p/let [_ (protocol/mkdir! this recycle-dir)
                handle (get-nfs-file-handle handle-path)
@@ -219,14 +219,14 @@
                content (.text file)
 
                bak-handle (get-nfs-file-handle (str "handle/" recycle-dir))
-               bak-filename (-> (fs2-path/relative-path repo-dir fpath)
+               bak-filename (-> (path/relative-path repo-dir fpath)
                                 (string/replace "/" "_")
                                 (string/replace "\\" "_"))
                _ (prn ::backup-file bak-filename)
                file-handle (.getFileHandle ^js bak-handle bak-filename #js {:create true})
                _ (utils/writeFile file-handle content)
 
-               parent-dir (fs2-path/parent fpath)
+               parent-dir (path/parent fpath)
                parent-handle (get-nfs-file-handle (str "handle/" parent-dir))
                _ (when parent-handle
                    (.removeEntry ^js parent-handle filename))]
@@ -241,7 +241,7 @@
 
   (read-file [_this dir path _options]
     (prn ::read-file dir path)
-    (let [fpath (fs2-path/path-join dir path)
+    (let [fpath (path/path-join dir path)
           handle-path (str "handle/" fpath)]
       (p/let [handle (or (get-nfs-file-handle handle-path)
                          (idb/get-item handle-path))
@@ -251,7 +251,7 @@
   (write-file! [_this repo dir path content opts]
     ;; TODO: file backup handling
     (prn ::write-file dir path)
-    (let [fpath (fs2-path/path-join dir path)
+    (let [fpath (path/path-join dir path)
           ext (util/get-file-ext path)
           file-handle-path (str "handle/" fpath)]
       (p/let [file-handle (get-nfs-file-handle file-handle-path)]
@@ -275,8 +275,8 @@
                   (db/set-file-content! repo path content)
                   (nfs-saved-handler repo path file)))))
           ;; file no-exist, write via parent dir handle
-          (p/let [basename (fs2-path/filename fpath)
-                  parent-dir (fs2-path/parent fpath)
+          (p/let [basename (path/filename fpath)
+                  parent-dir (path/parent fpath)
                   parent-dir-handle-path (str "handle/" parent-dir)
                   _ (prn ::debug-0 parent-dir-handle-path)
                   parent-dir-handle (get-nfs-file-handle parent-dir-handle-path)]
@@ -305,8 +305,8 @@
 
   (rename! [this repo old-path new-path]
     (p/let [repo-dir (config/get-repo-dir repo)
-            old-rpath (fs2-path/relative-path repo old-path)
-            new-rpath (fs2-path/relative-path repo new-path)
+            old-rpath (path/relative-path repo old-path)
+            new-rpath (path/relative-path repo new-path)
             old-content (protocol/read-file this repo old-rpath nil)
             _ (protocol/write-file! this repo repo-dir new-rpath old-content nil)
             _ (protocol/unlink! this repo old-path nil)]))
@@ -314,7 +314,8 @@
   (stat [_this fpath]
     (prn ::stat fpath)
     (if-let [handle (get-nfs-file-handle (str "handle/" fpath))]
-      (p/let [file (.getFile handle)]
+      (p/let [_ (verify-handle-permission handle true)
+              file (.getFile handle)]
         (let [get-attr #(gobj/get file %)]
           {:last-modified-at (get-attr "lastModified")
            :size (get-attr "size")

+ 5 - 5
src/main/frontend/fs/node.cljs

@@ -11,7 +11,7 @@
             [goog.object :as gobj]
             [lambdaisland.glogi :as log]
             [promesa.core :as p]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 (defn- contents-matched?
   [disk-content db-content]
@@ -33,7 +33,7 @@
 (defn- write-file-impl!
   [repo dir rpath content {:keys [ok-handler error-handler old-content skip-compare?]} stat]
   (prn ::write-file-impl repo dir rpath)
-  (let [file-fpath (fs2-path/path-join dir rpath)]
+  (let [file-fpath (path/path-join dir rpath)]
     (if skip-compare?
       (p/catch
        (p/let [result (ipc/ipc "writeFile" repo file-fpath content)]
@@ -108,14 +108,14 @@
   (read-file [_this dir path _options]
     (let [path (if (nil? dir)
                  path
-                 (fs2-path/path-join dir path))]
+                 (path/path-join dir path))]
       (ipc/ipc "readFile" path)))
   (write-file! [this repo dir path content opts]
-    (p/let [fpath (fs2-path/path-join dir path)
+    (p/let [fpath (path/path-join dir path)
             stat (p/catch
                   (protocol/stat this fpath)
                   (fn [_e] :not-found))
-            parent-dir (fs2-path/parent fpath)
+            parent-dir (path/parent fpath)
             _ (protocol/mkdir-recur! this parent-dir)]
       (write-file-impl! repo dir path content opts stat)))
   (rename! [_this _repo old-path new-path]

+ 2 - 3
src/main/frontend/fs/watcher_handler.cljs

@@ -6,7 +6,7 @@
             [frontend.db :as db]
             [frontend.db.model :as model]
             [frontend.fs :as fs]
-            [frontend.fs2.path :as fs2-path]
+            [logseq.common.path :as path]
             [frontend.handler.editor :as editor]
             [frontend.handler.file :as file-handler]
             [frontend.handler.page :as page-handler]
@@ -16,7 +16,6 @@
             [frontend.util.fs :as fs-util]
             [lambdaisland.glogi :as log]
             [logseq.graph-parser.config :as gp-config]
-            [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util.block-ref :as block-ref]
             [promesa.core :as p]))
 
@@ -125,7 +124,7 @@
                         (map first)
                         (filter #(string/starts-with? % (config/get-repo-dir graph))))]
       (p/let [files (fs/readdir dir :path-only? true)
-              files (map #(fs2-path/relative-path dir %) files)
+              files (map #(path/relative-path dir %) files)
               files (remove #(fs-util/ignored-path? dir %) files)
               deleted-files (set/difference (set db-files) (set files))]
         (when (seq deleted-files)

+ 0 - 36
src/main/frontend/fs2/path_test.cljs

@@ -1,36 +0,0 @@
-(ns frontend.fs2.path-test
-  (:require [cljs.test :refer [deftest is testing]]
-            [frontend.fs2.path :as path]))
-
-
-
-(deftest test-safe-file-name?
-  (testing "safe-file-name"
-    (is (path/safe-file-name? "foo"))
-    (is (path/safe-file-name? "foo bar"))
-    (is (path/safe-file-name? "foo-bar"))
-    (is (path/safe-file-name? "foo_bar"))
-    (is (path/safe-file-name? "foo.bar"))
-    (is (path/safe-file-name? "foo..bar"))
-    (is (path/safe-file-name? "foo...bar"))
-    (is (= nil (path/safe-file-name? "foo/bar")))
-    (is (not (path/safe-file-name? "foo?bar")))
-    (is (not (path/safe-file-name? "foo<bar")))
-    (is (not (path/safe-file-name? "foo>bar")))))
-
-
-(deftest path-join
-  (testing "join-path")
-  (is (= "foo/bar" (path/path-join ["foo" "bar"])))
-  (is (= "foo/bar" (path/path-join ["foo/" "bar"])))
-  (is (= "/foo/bar/baz/asdf" (path/path-join ["/foo/bar//baz/asdf/quux/.."]))))
-
-((deftest url-join-test
-   (testing "url-join"
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar" ["baz"])))
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar/" ["baz"])))
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar/" ["/baz"])))
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar" ["/baz"])))
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar" ["/baz/"])))
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar/" ["/baz/"])))
-     (is (= "https://foo.bar/baz" (path/url-join "https://foo.bar/" ["/baz"]))))))

+ 2 - 3
src/main/frontend/handler/code.cljs

@@ -8,8 +8,7 @@
             [frontend.state :as state]
             [goog.object :as gobj]
             [logseq.graph-parser.utf8 :as utf8]
-            [frontend.fs2.path :as fs2-path]
-            [frontend.components.content :as content]))
+            [logseq.common.path :as path]))
 
 (defn save-code-editor!
   []
@@ -42,7 +41,7 @@
             (let [path (:file-path config)
                   repo (state/get-current-repo)
                   repo-dir (config/get-repo-dir repo)
-                  rpath (fs2-path/trim-dir-prefix repo-dir path)
+                  rpath (path/trim-dir-prefix repo-dir path)
                   ;; old-content (db/get-file rpath)
                   _ (prn ::calc rpath)]
               (if rpath

+ 2 - 26
src/main/frontend/handler/common/file.cljs

@@ -1,15 +1,11 @@
 (ns frontend.handler.common.file
   "Common file related fns for handlers"
-  (:require [frontend.util :as util]
-            [frontend.config :as config]
+  (:require [frontend.config :as config]
             [frontend.state :as state]
             [frontend.db :as db]
-            ["/frontend/utils" :as utils]
-            [frontend.mobile.util :as mobile-util]
             [logseq.graph-parser :as graph-parser]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.config :as gp-config]
-            [frontend.fs.capacitor-fs :as capacitor-fs]
             [frontend.fs :as fs]
             [frontend.context.i18n :refer [t]]
             [clojure.string :as string]
@@ -55,27 +51,7 @@
   ([repo-url file-path content]
    (reset-file! repo-url file-path content {}))
   ([repo-url file-path content {:keys [verbose] :as options}]
-   (let [electron-local-repo? (and (util/electron?)
-                                   (config/local-db? repo-url))
-         repo-dir (config/get-repo-dir repo-url)
-         ;; use relpath
-         _ (comment cond
-                (and electron-local-repo?
-                     util/win32?
-                     (utils/win32 file))
-                file
-
-                (and electron-local-repo? (or
-                                           util/win32?
-                                           (not= "/" (first file))))
-                (str repo-dir "/" file)
-
-                (mobile-util/native-platform?)
-                (capacitor-fs/normalize-file-protocol-path repo-dir file)
-
-                :else
-                file)
-         _ (prn ::reset-file file-path)
+   (let [_ (prn ::reset-file file-path)
          new? (nil? (db/entity [:file/path file-path]))
          options (merge (dissoc options :verbose)
                         {:new? new?

+ 8 - 8
src/main/frontend/handler/editor.cljs

@@ -15,7 +15,7 @@
             [frontend.format.mldoc :as mldoc]
             [frontend.fs :as fs]
             [frontend.fs.nfs :as nfs]
-            [frontend.fs2.path :as fs2-path]
+            [logseq.common.path :as path]
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.block :as block-handler]
             [frontend.handler.common :as common-handler]
@@ -1387,7 +1387,7 @@
   [repo]
   (p/let [repo-dir (config/get-repo-dir repo)
           assets-dir "assets"
-          _ (fs/mkdir-if-not-exists (fs2-path/path-join repo-dir assets-dir))]
+          _ (fs/mkdir-if-not-exists (path/path-join repo-dir assets-dir))]
     (prn ::ensure-assets-dir repo-dir assets-dir)
     [repo-dir assets-dir]))
 
@@ -1395,7 +1395,7 @@
   "Get asset path from filename, ensure assets dir exists"
   [filename]
   (p/let [[repo-dir assets-dir] (ensure-assets-dir! (state/get-current-repo))]
-    (fs2-path/path-join repo-dir assets-dir filename)))
+    (path/path-join repo-dir assets-dir filename)))
 
 (defn save-assets!
   "Save incoming(pasted) assets to assets directory.
@@ -1446,7 +1446,7 @@
 
           (p/do! (js/console.debug "Debug: Writing Asset #" dir file-rpath)
                  (fs/write-file! repo dir file-rpath (.stream file) nil)
-                 [file-rpath file (fs2-path/path-join dir file-rpath) matched-alias])))))))
+                 [file-rpath file (path/path-join dir file-rpath) matched-alias])))))))
 
 (defonce *assets-url-cache (atom {}))
 
@@ -1470,7 +1470,7 @@
         (assets-handler/resolve-asset-real-path-url (state/get-current-repo) path)
 
         (util/electron?)
-        (fs2-path/path-join "assets://" full-path)
+        (path/path-join "assets://" full-path)
 
         (mobile-util/native-platform?)
         (mobile-util/convert-file-src full-path)
@@ -1501,10 +1501,10 @@
                           (second (re-find #"\((.+)\)$" full-text)))]
         (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)
+                            (path/url-to-path href)
                             (config/get-repo-fpath
                              repo
-                             (fs2-path/resolve-relative-path block-file-rpath href)))]
+                             (path/resolve-relative-path block-file-rpath href)))]
           (prn ::deleting href asset-fpath)
           (fs/unlink! repo asset-fpath nil))))))
 
@@ -1521,7 +1521,7 @@
                                      (config/get-repo-dir (state/get-current-repo))
                                      (config/get-pages-directory) "_.md")))]
     (let [repo-dir (config/get-repo-dir (state/get-current-repo))
-            current-file-fpath (fs2-path/path-join repo-dir current-file-rpath)]
+            current-file-fpath (path/path-join repo-dir current-file-rpath)]
         (util/get-relative-path current-file-fpath file-path))
     file-path))
 

+ 2 - 2
src/main/frontend/handler/events.cljs

@@ -71,7 +71,7 @@
             [logseq.graph-parser.config :as gp-config]
             [promesa.core :as p]
             [rum.core :as rum]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 ;; TODO: should we move all events here?
 
@@ -624,7 +624,7 @@
                     (update :path
                            (fn [path]
                              (when (string? path)
-                               (fs2-path/relative-path dir path)))))]
+                               (path/relative-path dir path)))))]
     (fs-watcher/handle-changed! type payload)
     (when (file-sync-handler/enable-sync?)
      (sync/file-watch-handler type payload))))

+ 2 - 2
src/main/frontend/handler/file.cljs

@@ -20,8 +20,8 @@
             [lambdaisland.glogi :as log]
             [promesa.core :as p]
             [frontend.mobile.util :as mobile-util]
-            [logseq.graph-parser.config :as gp-config]
-            ["path" :as path]))
+            [logseq.common.path :as path]
+            [logseq.graph-parser.config :as gp-config]))
 
 ;; TODO: extract all git ops using a channel
 

+ 7 - 7
src/main/frontend/handler/file_sync.cljs

@@ -1,6 +1,6 @@
 (ns frontend.handler.file-sync
   "Provides util handler fns for file sync"
-  (:require ["path" :as path]
+  (:require ["path" :as node-path]
             [cljs-time.format :as tf]
             [cljs.core.async :as async :refer [go <!]]
             [cljs.core.async.interop :refer [p->c]]
@@ -121,7 +121,7 @@
    (download-version-file graph-uuid file-uuid version-uuid false))
   ([graph-uuid file-uuid version-uuid silent-download?]
    (go
-     (let [key (path/join file-uuid version-uuid)
+     (let [key (node-path/join file-uuid version-uuid)
            r   (<! (sync/<download-version-files
                     sync/rsapi graph-uuid (config/get-repo-dir (state/get-current-repo)) [key]))]
        (if (instance? ExceptionInfo r)
@@ -131,7 +131,7 @@
                                 [:div "Downloaded version file at: "]
                                 [:div key]] :success false)))
        (when-not (instance? ExceptionInfo r)
-         (path/join "logseq" "version-files" key))))))
+         (node-path/join "logseq" "version-files" key))))))
 
 (defn- <list-file-local-versions
   [page]
@@ -139,11 +139,11 @@
     (when-let [path (-> page :block/file :file/path)]
       (let [base-path           (config/get-repo-dir (state/get-current-repo))
             rel-path            (string/replace-first path base-path "")
-            version-files-dir   (->> (path/join "logseq/version-files/local" rel-path)
-                                     path/parse
+            version-files-dir   (->> (node-path/join "logseq/version-files/local" rel-path)
+                                     node-path/parse
                                      (#(js->clj % :keywordize-keys true))
                                      ((juxt :dir :name))
-                                     (apply path/join base-path))
+                                     (apply node-path/join base-path))
             version-file-paths (<! (p->c (fs/readdir version-files-dir :path-only? true)))]
         (when-not (instance? ExceptionInfo version-file-paths)
           (when (seq version-file-paths)
@@ -152,7 +152,7 @@
               (fn [path]
                 (try
                   (let [create-time
-                        (-> (path/parse path)
+                        (-> (node-path/parse path)
                             (js->clj :keywordize-keys true)
                             :name
                             (#(tf/parse (tf/formatter "yyyy-MM-dd'T'HH_mm_ss.SSSZZ") %)))]

+ 3 - 3
src/main/frontend/handler/global_config.cljs

@@ -9,7 +9,7 @@
             [shadow.resource :as rc]
             [clojure.edn :as edn]
             [electron.ipc :as ipc]
-            ["path" :as path]))
+            [logseq.common.path :as path]))
 
 ;; Use defonce to avoid broken state on dev reload
 ;; Also known as home directory a.k.a. '~'
@@ -24,11 +24,11 @@
 
 (defn global-config-dir
   []
-  (path/join @root-dir "config"))
+  (path/path-join @root-dir "config"))
 
 (defn global-config-path
   []
-  (path/join @root-dir "config" "config.edn"))
+  (path/path-join @root-dir "config" "config.edn"))
 
 (defn- set-global-config-state!
   [content]

+ 6 - 6
src/main/frontend/handler/repo.cljs

@@ -31,7 +31,7 @@
             [clojure.core.async :as async]
             [frontend.mobile.util :as mobile-util]
             [medley.core :as medley]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 ;; Project settings should be checked in two situations:
 ;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
@@ -51,7 +51,7 @@
                               "org" (rc/inline "contents.org")
                               "markdown" (rc/inline "contents.md")
                               "")]
-        (p/let [_ (fs/mkdir-if-not-exists (fs2-path/path-join repo-dir pages-dir))
+        (p/let [_ (fs/mkdir-if-not-exists (path/path-join repo-dir pages-dir))
                 file-exists? (fs/create-if-not-exists repo-url repo-dir file-rpath default-content)]
           (when-not file-exists?
             (file-common-handler/reset-file! repo-url file-rpath default-content)))))))
@@ -63,7 +63,7 @@
         path (str config/app-name "/" config/custom-css-file)
         file-rpath path
         default-content ""]
-    (p/let [_ (fs/mkdir-if-not-exists (fs2-path/path-join repo-dir config/app-name))
+    (p/let [_ (fs/mkdir-if-not-exists (path/path-join repo-dir config/app-name))
             file-exists? (fs/create-if-not-exists repo-url repo-dir file-rpath default-content)]
       (when-not file-exists?
         (file-common-handler/reset-file! repo-url path default-content)))))
@@ -73,7 +73,7 @@
   (spec/validate :repos/url repo-url)
   (let [repo-dir (config/get-repo-dir repo-url)
         file-rpath (str (config/get-pages-directory) "/how_to_make_dummy_notes.md")]
-    (p/let [_ (fs/mkdir-if-not-exists (fs2-path/path-join repo-dir (config/get-pages-directory)))
+    (p/let [_ (fs/mkdir-if-not-exists (path/path-join repo-dir (config/get-pages-directory)))
             _file-exists? (fs/create-if-not-exists repo-url repo-dir file-rpath content)]
       (file-common-handler/reset-file! repo-url file-rpath content))))
 
@@ -99,13 +99,13 @@
 
                     :else
                     default-content)
-          file-rpath (fs2-path/path-join (config/get-journals-directory) (str file-name "."
+          file-rpath (path/path-join (config/get-journals-directory) (str file-name "."
                                                                               (config/get-file-extension format)))
           page-exists? (db/entity repo-url [:block/name (util/page-name-sanity-lc title)])
           empty-blocks? (db/page-empty? repo-url (util/page-name-sanity-lc title))]
       (when (or empty-blocks? (not page-exists?))
         (p/let [_ (nfs/check-directory-permission! repo-url)
-                _ (fs/mkdir-if-not-exists (fs2-path/path-join repo-dir (config/get-journals-directory)))
+                _ (fs/mkdir-if-not-exists (path/path-join repo-dir (config/get-journals-directory)))
                 file-exists? (fs/file-exists? repo-dir file-rpath)]
           (when-not file-exists?
             (p/let [_ (file-common-handler/reset-file! repo-url file-rpath content)]

+ 2 - 2
src/main/frontend/handler/repo_config.cljs

@@ -7,7 +7,7 @@
             [frontend.config :as config]
             [frontend.db :as db]
             [frontend.fs :as fs]
-            [frontend.fs2.path :as fs2-path]
+            [logseq.common.path :as path]
             [frontend.handler.common.file :as file-common-handler]
             [frontend.handler.notification :as notification]
             [frontend.spec :as spec]
@@ -41,7 +41,7 @@
   (spec/validate :repos/url repo-url)
   (let [repo-dir (config/get-repo-dir repo-url)
         app-dir config/app-name
-        dir (fs2-path/path-join repo-dir app-dir)]
+        dir (path/path-join repo-dir app-dir)]
     (p/let [_ (fs/mkdir-if-not-exists dir)]
       (let [default-content config/config-default-content
             path (str app-dir "/" config/config-file)]

+ 2 - 2
src/main/frontend/handler/ui.cljs

@@ -15,7 +15,7 @@
             [rum.core :as rum]
             [electron.ipc :as ipc]
             [promesa.core :as p]
-            [frontend.fs2.path :as fs2-path]))
+            [logseq.common.path :as path]))
 
 (defn- get-css-var-value
   [var-name]
@@ -157,7 +157,7 @@
                     (ask-allow))
             (load href #(do (js/console.log "[custom js]" href) (execed))))
           (let [repo-dir (config/get-repo-dir (state/get-current-repo))
-                rpath (fs2-path/relative-path repo-dir href)]
+                rpath (path/relative-path repo-dir href)]
             (p/let [exists? (fs/file-exists? repo-dir rpath)]
               (when exists?
                 (util/p-handle

+ 1 - 2
src/main/frontend/handler/web/nfs.cljs

@@ -1,7 +1,6 @@
 (ns frontend.handler.web.nfs
   "The File System Access API, https://web.dev/file-system-access/."
   (:require ["/frontend/utils" :as utils]
-            [cljs-bean.core :as bean]
             [clojure.set :as set]
             [clojure.string :as string]
             [frontend.config :as config]
@@ -210,7 +209,7 @@
    (when-let [dir-result-fn
               (and path (fn [{:keys [nfs?]}]
                           (p/let [files-result (fs/get-files path)]
-                            [path (:files files-result)])))]
+                            files-result)))]
      (ls-dir-files-with-handler!
       (:ok-handler opts)
       (merge {:dir-result-fn dir-result-fn} opts)))))

+ 6 - 5
src/main/frontend/modules/file/core.cljs

@@ -3,13 +3,14 @@
             [frontend.config :as config]
             [frontend.date :as date]
             [frontend.db :as db]
+            [frontend.db.model :as model]
             [frontend.db.utils :as db-utils]
+            [frontend.handler.file :as file-handler]
             [frontend.modules.file.uprint :as up]
             [frontend.state :as state]
-            [frontend.util.property :as property]
             [frontend.util.fs :as fs-util]
-            [frontend.handler.file :as file-handler]
-            [frontend.db.model :as model]))
+            [frontend.util.property :as property]
+            [logseq.common.path :as path]))
 
 (defn- indented-block-content
   [content spaces-tabs]
@@ -107,7 +108,7 @@
 
 (defn- transact-file-tx-if-not-exists!
   [page-block ok-handler]
-  (when-let [repo (state/get-current-repo)]
+  (when-let [_repo (state/get-current-repo)]
     (when (:block/name page-block)
       (let [format (name (get page-block :block/format
                               (state/get-preferred-format)))
@@ -125,7 +126,7 @@
                       whiteboard-page? (config/get-whiteboards-directory)
                       :else            (config/get-pages-directory))
             ext (if (= format "markdown") "md" format)
-            file-rpath (str sub-dir "/" filename "." ext) ;; FIXME: use path-join
+            file-rpath (path/path-join sub-dir (str filename "." ext))
             file {:file/path file-rpath}
             tx [{:file/path file-rpath}
                 {:block/name (:block/name page-block)

+ 1 - 2
src/main/frontend/util/fs.cljs

@@ -10,8 +10,7 @@
             [frontend.fs :as fs]
             [frontend.config :as config]
             [promesa.core :as p]
-            [cljs.reader :as reader]
-            [frontend.fs2.path :as fs2-path]))
+            [cljs.reader :as reader]))
 
 ;; NOTE: This is not the same ignored-path? as src/electron/electron/utils.cljs.
 ;;       The assets directory is ignored.