fix: delete remote files(old format) when upgrading file format

This commit is contained in:
Tienson Qin
2022-11-25 12:13:20 +08:00
parent 95a8783a0b
commit 1796b20542
3 changed files with 36 additions and 32 deletions

View File

@@ -13,6 +13,7 @@
[frontend.context.i18n :refer [t]]
[rum.core :as rum]
[frontend.handler.file-sync :as file-sync-handler]
[frontend.fs.sync :as sync]
[frontend.handler.notification :as notification]))
(defn- ask-for-re-index
@@ -28,15 +29,26 @@
(defn- <close-modal-on-done
"Ask users to re-index when the modal is exited"
[sync?]
(async/go (state/close-settings!)
(async/<! (async/timeout 100)) ;; modal race condition requires investigation
(if sync?
(notification/show!
[:div "Please re-index this graph after all the changes are synced."]
:warning
false)
(ask-for-re-index))))
[sync? rename-items]
(async/go
(state/close-modal!)
(async/<! (async/timeout 100)) ;; modal race condition requires investigation
(let [renamed-paths (keep (fn [{:keys [file file-name target]}]
(when (not= file-name target)
(sync/relative-path (:file/path file)))) rename-items)
graph-txid (second @sync/graphs-txid)]
(when (and (seq renamed-paths) sync? graph-txid)
(async/<!
(sync/<delete-remote-files-control
sync/remoteapi
graph-txid
renamed-paths))))
(if sync?
(notification/show!
[:div "Please re-index this graph after all the changes are synced."]
:warning
false)
(ask-for-re-index))))
(rum/defc legacy-warning
[repo *target-format *dir-format *solid-format]
@@ -123,10 +135,11 @@
(merge ret {:page page :file file}))))
(remove nil?))
sync? (file-sync-handler/current-graph-sync-on?)
<rename-all #(async/go (doseq [{:keys [file target status]} rename-items]
(when (not= status :unreachable)
(async/<! (p->c (page-handler/rename-file! file target (constantly nil) true)))))
(<close-modal-on-done sync?))]
<rename-all #(async/go
(doseq [{:keys [file target status]} rename-items]
(when (not= status :unreachable)
(async/<! (p->c (page-handler/rename-file! file target (constantly nil) true)))))
(<close-modal-on-done sync? rename-items))]
(if (not-empty rename-items)
[:div ;; Normal UX stage 2: close stage 1 UI, show the action description as admolition
@@ -154,12 +167,7 @@
rename-fn #(page-handler/rename-file! file target rm-item-fn)
rename-but [:a {:on-click rename-fn
:title (t :file-rn/apply-rename)}
[:span (t :file-rn/rename src-file-name tgt-file-name)]]
rename-but-sm (ui/button
(t :file-rn/rename-sm)
:on-click rename-fn
:class "text-sm p-1 mr-1"
:style {:word-break "normal"})]
[:span (t :file-rn/rename src-file-name tgt-file-name)]]]
[:tr {:key (:block/name page)}
[:td [:div [:p "📄 " old-title]]
(case status
@@ -168,6 +176,5 @@
[:p (t :file-rn/otherwise-breaking) " \"" changed-title \"]]
:unreachable
[:div [:p "🔴 " (t :file-rn/unreachable-title changed-title)]]
[:div [:p "🟢 " (t :file-rn/optional-rename) rename-but]])]
[:td rename-but-sm]]))]]]
[:div [:p "🟢 " (t :file-rn/optional-rename) rename-but]])]]))]]]
[:div "🎉 " (t :file-rn/no-action)]))]]))

View File

@@ -132,7 +132,6 @@
:file-rn/all-action "Apply all Actions!"
:file-rn/select-format "(Developer Mode Option, Dangerous!) Select filename format"
:file-rn/rename "rename file \"{1}\" to \"{2}\""
:file-rn/rename-sm "Rename"
:file-rn/apply-rename "Apply the file rename operation"
:file-rn/affected-pages "Affected Pages after the format change"
:file-rn/suggest-rename "Action required: "
@@ -1273,7 +1272,6 @@
:file-rn/otherwise-breaking "Ou le titre deviendra"
:file-rn/re-index "La réindexation est fortement recommandée après que les fichiers aient été renommés, puis sur les autres postes après synchronisation."
:file-rn/rename "renommer le fichier \"{1}\" en \"{2}\""
:file-rn/rename-sm "Renommer"
:file-rn/select-confirm-proceed "Dev: format d'écriture"
:file-rn/select-format "(Option du Mode Developpeur, Danger !) Sélectionnez le format de nom de fichier"
:file-rn/suggest-rename "Action requise : "
@@ -1585,7 +1583,6 @@
:file-rn/all-action "应用所有操作!"
:file-rn/select-format "(开发者模式选项,危险!) 选择文件名格式"
:file-rn/rename "重命名文件 \"{1}\" 到 \"{2}\""
:file-rn/rename-sm "重命名"
:file-rn/apply-rename "应用文件重命名操作"
:file-rn/affected-pages "格式改变后,影响的文件"
:file-rn/suggest-rename "需要的操作: "
@@ -2270,7 +2267,6 @@
:file-rn/all-action "¡Aplicar todas las acciones!"
:file-rn/select-format "(Opción modo desarrollador, ¡peligroso!) Seccione el formato de nombre de archivo"
:file-rn/rename "Renombrar \"{1}\" a \"{2}\""
:file-rn/rename-sm "Renombrar"
:file-rn/apply-rename "Aplicar la operación de cambio de nombre de archivo"
:file-rn/affected-pages "Páginas afectadas después del cambio de formato"
:file-rn/suggest-rename "Acción necesaria: "
@@ -4620,7 +4616,6 @@
:file-rn/all-action "Tüm Eylemleri Uygula!"
:file-rn/select-format "(Geliştirici Modu Seçeneği, Tehlikeli!) Dosya adı biçimini seçin"
:file-rn/rename "\"{1}\" dosyasını \"{2}\" olarak yeniden adlandır"
:file-rn/rename-sm "Yeniden adlandır"
:file-rn/apply-rename "Dosya yeniden adlandırma işlemini uygula"
:file-rn/affected-pages "Biçim değişikliğinden sonra Etkilenen Sayfalar"
:file-rn/suggest-rename "Eylem gereklidir: "

View File

@@ -15,10 +15,10 @@
(set-config! repo :file/name-format format))
(defn- calc-current-name
"If the file body is parsed as the same page name, but the page name has a
different file sanitization result under the current sanitization form, return
"If the file body is parsed as the same page name, but the page name has a
different file sanitization result under the current sanitization form, return
the new file name.
Return:
Return:
the file name for the page name under the current file naming rules, or `nil`
if no change of path happens"
[format file-body prop-title]
@@ -33,7 +33,7 @@
(defn- calc-previous-name
"We want to recover user's title back under new file name sanity rules.
Return:
Return:
the file name for that page name under the current file naming rules,
and the new title if no action applied, or `nil` if no break change happens"
[old-format new-format file-body]
@@ -72,7 +72,7 @@
[old-format new-format file-body prop-title]
;; dont rename journal page. officially it's stored as `yyyy_mm_dd`
;; If it's a journal file imported with custom :journal/page-title-format,
;; and it includes reserved characters, format config change / file renaming is required.
;; and it includes reserved characters, format config change / file renaming is required.
;; It's about user's own data management decision and should be handled
;; by user manually.
;; the 'expected' title of the user when updating from the previous format, or title will be broken in new format
@@ -88,7 +88,7 @@
ret)))
(defn calc-rename-target
"Return the renaming status and new file body to recover the original title of the file in previous version.
"Return the renaming status and new file body to recover the original title of the file in previous version.
The return title should be the same as the title in the index file in the previous version.
return nil if no rename is needed.
page: the page entity
@@ -96,6 +96,7 @@
old-format, new-format: the filename formats
Return:
{:status :informal | :breaking | :unreachable
:file-name original file name
:target the new file name
:old-title the old title
:changed-title the new title} | nil"
@@ -113,6 +114,7 @@
manual-prop-title?
(fs-util/include-reserved-chars? file-body))
{:status :informal
:file-name file-body
:target (fs-util/file-name-sanity file-body new-format)
:old-title prop-title
:changed-title prop-title})))