|
@@ -194,62 +194,63 @@
|
|
|
reset? false
|
|
|
update-db? true}
|
|
|
:as opts}]
|
|
|
- ;; update db
|
|
|
- (when update-db?
|
|
|
- (doseq [[path content] files]
|
|
|
- (if reset?
|
|
|
- (reset-file! repo path content)
|
|
|
- (db/set-file-content! repo path content))))
|
|
|
+ ;; old file content
|
|
|
+ (let [file->content (let [paths (map first files)]
|
|
|
+ (zipmap paths
|
|
|
+ (map (fn [path] (db/get-file-no-sub repo path)) paths)))]
|
|
|
+ ;; update db
|
|
|
+ (when update-db?
|
|
|
+ (doseq [[path content] files]
|
|
|
+ (if reset?
|
|
|
+ (reset-file! repo path content)
|
|
|
+ (db/set-file-content! repo path content))))
|
|
|
|
|
|
- (when-let [chan (state/get-file-write-chan)]
|
|
|
- (async/put! chan [repo files opts])))
|
|
|
+ (when-let [chan (state/get-file-write-chan)]
|
|
|
+ (async/put! chan [repo files opts file->content]))))
|
|
|
|
|
|
(defn alter-files-handler!
|
|
|
[repo files {:keys [add-history? update-status? git-add-cb reset?]
|
|
|
:or {add-history? true
|
|
|
update-status? true
|
|
|
- reset? false}}]
|
|
|
- (p/let [file->content (let [paths (map first files)]
|
|
|
- (zipmap paths
|
|
|
- (map (fn [path] (db/get-file-no-sub repo path)) paths)))]
|
|
|
- (let [write-file-f (fn [[path content]]
|
|
|
- (let [original-content (get file->content path)]
|
|
|
- (-> (p/let [_ (fs/check-directory-permission! repo)]
|
|
|
- (fs/write-file repo (util/get-repo-dir repo) path content
|
|
|
- {:old-content original-content
|
|
|
- :last-modified-at (db/get-file-last-modified-at repo path)}))
|
|
|
- (p/catch (fn [error]
|
|
|
- (log/error :write-file/failed {:path path
|
|
|
- :content content
|
|
|
- :error error}))))))
|
|
|
- git-add-f (fn []
|
|
|
- (let [add-helper
|
|
|
- (fn []
|
|
|
- (map
|
|
|
- (fn [[path content]]
|
|
|
- (git-handler/git-add repo path update-status?))
|
|
|
- files))]
|
|
|
- (-> (p/all (add-helper))
|
|
|
- (p/then (fn [_]
|
|
|
- (when git-add-cb
|
|
|
- (git-add-cb))))
|
|
|
- (p/catch (fn [error]
|
|
|
- (println "Git add failed:")
|
|
|
- (js/console.error error)))))
|
|
|
- (ui-handler/re-render-file!)
|
|
|
- (when add-history?
|
|
|
- (let [files-tx (mapv (fn [[path content]]
|
|
|
- (let [original-content (get file->content path)]
|
|
|
- [path original-content content])) files)]
|
|
|
- (history/add-history! repo files-tx))))]
|
|
|
- (-> (p/all (map write-file-f files))
|
|
|
- (p/then (fn []
|
|
|
- (git-add-f)
|
|
|
- ;; TODO: save logseq/metadata
|
|
|
-))
|
|
|
- (p/catch (fn [error]
|
|
|
- (println "Alter files failed:")
|
|
|
- (js/console.error error)))))))
|
|
|
+ reset? false}} file->content]
|
|
|
+ (let [write-file-f (fn [[path content]]
|
|
|
+ (let [original-content (get file->content path)]
|
|
|
+ (prn {:original-content original-content})
|
|
|
+ (-> (p/let [_ (fs/check-directory-permission! repo)]
|
|
|
+ (fs/write-file repo (util/get-repo-dir repo) path content
|
|
|
+ {:old-content original-content
|
|
|
+ :last-modified-at (db/get-file-last-modified-at repo path)}))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (log/error :write-file/failed {:path path
|
|
|
+ :content content
|
|
|
+ :error error}))))))
|
|
|
+ git-add-f (fn []
|
|
|
+ (let [add-helper
|
|
|
+ (fn []
|
|
|
+ (map
|
|
|
+ (fn [[path content]]
|
|
|
+ (git-handler/git-add repo path update-status?))
|
|
|
+ files))]
|
|
|
+ (-> (p/all (add-helper))
|
|
|
+ (p/then (fn [_]
|
|
|
+ (when git-add-cb
|
|
|
+ (git-add-cb))))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (println "Git add failed:")
|
|
|
+ (js/console.error error)))))
|
|
|
+ (ui-handler/re-render-file!)
|
|
|
+ (when add-history?
|
|
|
+ (let [files-tx (mapv (fn [[path content]]
|
|
|
+ (let [original-content (get file->content path)]
|
|
|
+ (prn "content changed? " (not= original-content content))
|
|
|
+ [path original-content content])) files)]
|
|
|
+ (history/add-history! repo files-tx))))]
|
|
|
+ (-> (p/all (map write-file-f files))
|
|
|
+ (p/then (fn []
|
|
|
+ (git-add-f)))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (println "Alter files failed:")
|
|
|
+ (js/console.error error))))))
|
|
|
|
|
|
(defn remove-file!
|
|
|
[repo file]
|