From 34d3ffe1228d2faf9764c64923f9d111de051ad6 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 6 Sep 2022 17:29:36 +0800 Subject: [PATCH] fix: sync allows to pick a non-empty folder to sync with remote --- src/main/frontend/components/file_sync.cljs | 56 ++++++++++----------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/main/frontend/components/file_sync.cljs b/src/main/frontend/components/file_sync.cljs index ba1c6a7680..688614749d 100644 --- a/src/main/frontend/components/file_sync.cljs +++ b/src/main/frontend/components/file_sync.cljs @@ -340,39 +340,37 @@ [:div.-mt-1 (ui/button - (str "Open a local directory") - :class "w-full rounded-t-none py-4" - :on-click #(-> (page-handler/ls-dir-files! - (fn [{:keys [url]}] - (file-sync-handler/init-remote-graph url) - ;; TODO: wait for switch done - (js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200)) + (str "Open a local directory") + :class "w-full rounded-t-none py-4" + :on-click #(page-handler/ls-dir-files! + (fn [{:keys [url]}] + (file-sync-handler/init-remote-graph url) + ;; TODO: wait for switch done + (js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200)) - {:empty-dir?-or-pred - (fn [ret] - (let [empty-dir? (nil? (second ret))] - (if-let [root (first ret)] + {:empty-dir?-or-pred + (fn [ret] + (let [empty-dir? (nil? (second ret))] + (if-let [root (first ret)] - ;; verify directory - (-> (if empty-dir? - (p/resolved nil) - (if (util/electron?) - (ipc/ipc :readGraphTxIdInfo root) - (fs-util/read-graph-txid-info root))) + ;; verify directory + (-> (if empty-dir? + (p/resolved nil) + (if (util/electron?) + (ipc/ipc :readGraphTxIdInfo root) + (fs-util/read-graph-txid-info root))) - (p/then (fn [^js info] - (when (and (not empty-dir?) - (or (nil? info) - (nil? (second info)) - (not= (second info) (:GraphUUID graph)))) - (throw (js/Error. "AssertDirectoryError")))))) + (p/then (fn [^js info] + (when (and (not empty-dir?) + (or (nil? info) + (nil? (second info)) + (not= (second info) (:GraphUUID graph)))) + (if (js/confirm "This directory is not empty, are you sure to sync the remote graph with it? Make sure to back up the directory first.") + (p/resolved nil) + (throw (js/Error. nil))))))) - ;; cancel pick a directory - (throw (js/Error. nil)))))}) - - (p/catch (fn [^js e] - (when (= "AssertDirectoryError" (.-message e)) - (notifications/show! "Please select an empty directory or an existing remote graph!" :error)))))) + ;; cancel pick a directory + (throw (js/Error. nil)))))})) [:p.text-xs.opacity-50.px-1 (ui/icon "alert-circle") " An empty directory or an existing remote graph!"]]]) (defn pick-dest-to-sync-panel [graph]