mirror of https://github.com/logseq/logseq
fix(fs): global file writing in code editor
parent
3c0973013b
commit
98f4236309
|
@ -86,8 +86,8 @@
|
|||
(not (string/starts-with? path "/"))
|
||||
[repo-dir path]
|
||||
|
||||
:else
|
||||
["" path])]
|
||||
:else ;; global file on native platform
|
||||
[nil path])]
|
||||
(when (and format (contains? (gp-config/text-formats) format))
|
||||
(p/let [content (fs/read-file dir path)]
|
||||
(reset! *content (or content ""))))
|
||||
|
@ -105,7 +105,7 @@
|
|||
[:div.file {:id (str "file-edit-wrapper-" random-id)
|
||||
:key path}
|
||||
[:h1.title
|
||||
[:bdi path]]
|
||||
[:bdi (or original-name path)]]
|
||||
(when original-name
|
||||
[:div.text-sm.mb-4.ml-1 "Page: "
|
||||
[:a.bg-base-2.p-1.ml-1 {:style {:border-radius 4}
|
||||
|
|
|
@ -344,6 +344,7 @@
|
|||
;; - `logseq_local_/absolute/path/to/graph` => local graph, native fs backend
|
||||
;; - `logseq_local_x:/absolute/path/to/graph` => local graph, native fs backend, on Windows
|
||||
;; - `logseq_local_GraphName` => local graph, browser fs backend
|
||||
;; - Use `""` while writing global files
|
||||
|
||||
(defonce idb-db-prefix "logseq-db/")
|
||||
(defonce local-db-prefix "logseq_local_")
|
||||
|
|
|
@ -215,7 +215,9 @@
|
|||
(mkdir! dir))))
|
||||
(p/catch (fn [error] (js/console.error error)))))
|
||||
|
||||
;; FIXME: counterintuitive return value
|
||||
(defn create-if-not-exists
|
||||
"Create a file if it doesn't exist. return false on written, true on already exists"
|
||||
([repo dir path]
|
||||
(create-if-not-exists repo dir path ""))
|
||||
([repo dir path initial-content]
|
||||
|
|
|
@ -41,9 +41,7 @@
|
|||
(let [path (:file-path config)
|
||||
repo (state/get-current-repo)
|
||||
repo-dir (config/get-repo-dir repo)
|
||||
rpath (path/trim-dir-prefix repo-dir path)
|
||||
;; old-content (db/get-file rpath)
|
||||
_ (prn ::calc rpath)]
|
||||
rpath (path/trim-dir-prefix repo-dir path)]
|
||||
(if rpath
|
||||
;; in-db file
|
||||
(let [old-content (db/get-file rpath)]
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
Unlike repo config, this also manages a directory for configuration. This
|
||||
component depends on a repo."
|
||||
(:require [frontend.fs :as fs]
|
||||
[frontend.handler.common.file :as file-common-handler]
|
||||
[frontend.state :as state]
|
||||
[promesa.core :as p]
|
||||
[shadow.resource :as rc]
|
||||
|
@ -43,17 +42,15 @@
|
|||
(let [config-dir (global-config-dir)
|
||||
config-path (global-config-path)]
|
||||
(p/let [_ (fs/mkdir-if-not-exists config-dir)
|
||||
file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
|
||||
file-exists? (fs/create-if-not-exists repo-url nil config-path default-content)]
|
||||
(when-not file-exists?
|
||||
(file-common-handler/reset-file! repo-url config-path default-content)
|
||||
(set-global-config-state! default-content)))))
|
||||
|
||||
(defn restore-global-config!
|
||||
"Sets global config state from config file"
|
||||
[]
|
||||
(let [config-dir (global-config-dir)
|
||||
config-path (global-config-path)]
|
||||
(p/let [config-content (fs/read-file config-dir config-path)]
|
||||
(let [config-path (global-config-path)]
|
||||
(p/let [config-content (fs/read-file nil config-path)]
|
||||
(set-global-config-state! config-content))))
|
||||
|
||||
(defn start
|
||||
|
@ -69,6 +66,7 @@
|
|||
(reset! root-dir root-dir'))
|
||||
(restore-global-config!)
|
||||
(create-global-config-file-if-not-exists repo)
|
||||
;; FIXME: should use a file watcher instead of dir watcher
|
||||
(fs/watch-dir! (global-config-dir) {:global-dir true}))
|
||||
(p/timeout 6000)
|
||||
(p/catch (fn [e]
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
(set-files-aux! handles)))
|
||||
|
||||
;; TODO: extract code for `ls-dir-files` and `reload-dir!`
|
||||
(defn ^:large-vars/cleanup-todo ls-dir-files-with-handler!
|
||||
(defn ls-dir-files-with-handler!
|
||||
"Read files from directory and setup repo (for the first time setup a repo)"
|
||||
([ok-handler] (ls-dir-files-with-handler! ok-handler nil))
|
||||
([ok-handler {:keys [on-open-dir dir-result-fn picked-root-fn dir]}]
|
||||
|
@ -147,11 +147,11 @@
|
|||
(prn ::begin-hanlding-files dir-name)
|
||||
(when-not (string/blank? dir-name)
|
||||
(p/let [; handle/logseq_local_dir-name
|
||||
_ (when-let [root-handle-path (and nfs?
|
||||
(str config/local-handle-prefix dir-name))]
|
||||
(prn ::saving-handle-to-idb)
|
||||
;;_ (when-let [root-handle-path (and nfs?
|
||||
;; (str config/local-handle-prefix dir-name))]
|
||||
;;(prn ::saving-handle-to-idb)
|
||||
; (idb/set-item! root-handle-path (str "handle/" root-handle)))
|
||||
(nfs/save-root-handle-to-idb! repo root-handle))
|
||||
; (nfs/save-root-handle-to-idb! repo root-handle))
|
||||
; (idb/set-item! root-handle-path (str "handle/" root-handle))
|
||||
; ; (nfs/add-nfs-file-handle! root-handle-path root-handle)
|
||||
; )
|
||||
|
@ -243,7 +243,6 @@
|
|||
(defn- handle-diffs!
|
||||
"Compute directory diffs and handle them."
|
||||
[repo nfs? old-files new-files re-index? ok-handler]
|
||||
(prn ::handle-diff repo old-files new-files)
|
||||
(let [get-last-modified-at (fn [path] (some (fn [file]
|
||||
(when (= path (:file/path file))
|
||||
(:file/last-modified-at file)))
|
||||
|
|
Loading…
Reference in New Issue