Skip to content

Commit

Permalink
fix: Handle the migrate no permission case
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jan 25, 2024
1 parent 78e58a4 commit c3011a3
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions xmcl-keystone-ui/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ dataMigration:
migrationDestinationIsNotEmptyDirectory: >-
Das Übertragungsziel ist kein leeres Verzeichnis! Stellen Sie sicher, dass
ein leeres Verzeichnis ausgewählt ist!
migrationNoPermission: >-
Keine Berechtigung zum Umbenennen des alten Verzeichnisses in ein neues
Verzeichnis!
Bitte stellen Sie sicher, dass der Launcher Zugriff auf beide Orte hat!
placeholder: Klicken Sie hier, um einen Katalog auszuwählen
setRootCause: |-
Sie verlieren Daten (Maps, Texture Packs, Mods), wenn Sie den
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ dataMigration:
migrationDestinationIsNotEmptyDirectory: >-
Migration destination is not an empty directory! Please make sure you select
an empty directory!
migrationNoPermission: >-
No permission to rename the old directory to new directory! Please make sure
the launcher has access to both places!
placeholder: Please click here to select directory
setRootCause: >-
You will loose your data (Maps, Resource Packs, Mods) if you close the
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ dataMigration:
migrationDestinationIsNotEmptyDirectory: >-
¡El destino de migración no es un directorio vacío! ¡Asegúrese de
seleccionar un directorio vacío!
migrationNoPermission: |-
¡No hay permiso para cambiar el nombre del directorio antiguo al nuevo!
¡Asegúrese de que el lanzador tenga acceso a ambos lugares!
placeholder: Haga clic aquí para seleccionar el directorio
setRootCause: >-
¡Perderá sus datos (Mapas, Paquetes de Recursos, Mods) si cierra el Launcher
Expand Down
1 change: 1 addition & 0 deletions xmcl-keystone-ui/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ dataMigration:
migrationDestinationIsNotEmptyDirectory: |-
La destination de la migration n'est pas un répertoire vide !
Assurez-vous de sélectionner un répertoire vide !
migrationNoPermission: "Aucune autorisation pour renommer l'ancien répertoire en nouveau répertoire\_! \nVeuillez vous assurer que le lanceur a accès aux deux endroits\_!"
placeholder: Veuillez cliquer ici pour sélectionner le répertoire
setRootCause: >-
Vous perdrez vos données (cartes, packs de ressources, mods) si vous fermez
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ dataMigration:
migrationDestinationIsNotEmptyDirectory: >-
Место переноса не является пустым каталогом! Убедитесь что выбран пустой
каталог!
migrationNoPermission: |-
Нет разрешения на переименование старого каталога в новый!
Пожалуйста, убедитесь, что программа запуска имеет доступ к обоим местам!
placeholder: Нажмите здесь, чтобы выбрать каталог
setRootCause: >-
Вы потеряете свои данные (карты, текстурпаки, моды), если закроете лаунчер
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ dataMigration:
migrationDestinationIsNotEmptyDirectory: >-
Місце перенесення не є пустим каталогом! Переконайтеся, що обрано порожній
каталог!
migrationNoPermission: |-
Немає дозволу на перейменування старого каталогу на новий!
Переконайтеся, що програма запуску має доступ до обох місць!
placeholder: Натисніть тут, щоб вибрати каталог
setRootCause: |-
Ви втратите дані (карти, текстурпаки, моди), якщо закриєте
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ dataMigration:
directoryCriteriaHint: 请确保你选择的新的文件夹是一个<span class="font-bold text-lg mx-1">空</span>文件夹。
migrationDestinationIsFile: 迁移目标地址是个文件而不是文件夹!请重新选择一个空的文件夹!
migrationDestinationIsNotEmptyDirectory: 迁移目标不是一个空的文件夹!请确保你选择了一个空的文件夹!
migrationNoPermission: |-
没有权限将旧目录重命名为新目录!
请确保启动器可以访问这两个地方!
placeholder: 点击来选择新的根目录
setRootCause: 请确保启动器在此过程中不被中断,不然您的数据可能丢失
setRootDescription: 这将改变启动器的存储根目录。
Expand Down
2 changes: 2 additions & 0 deletions xmcl-keystone-ui/src/views/SettingMigrationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ const { refresh: apply, refreshing: migrating } = useRefreshable(async () => {
errorText.value = t('dataMigration.migrationDestinationIsFile')
} else if (e.exception.type === 'migrationDestinationIsNotEmptyDirectory') {
errorText.value = t('dataMigration.migrationDestinationIsNotEmptyDirectory')
} else if (e.exception.type === 'migrationNoPermission') {
errorText.value = t('dataMigration.migrationNoPermission')
} else {
errorText.value = t('dataMigration.unknownError')
}
Expand Down
7 changes: 7 additions & 0 deletions xmcl-runtime-api/src/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ export type BaseServiceExceptions = {
*/
type: 'migrationDestinationIsNotEmptyDirectory'
destination: string
} | {
/**
* Throw rename has no permission.
*/
type: 'migrationNoPermission'
source: string
destination: string
}

export class BaseServiceException extends Exception<BaseServiceExceptions> { }
Expand Down
10 changes: 8 additions & 2 deletions xmcl-runtime/base/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,22 @@ export class BaseService extends AbstractService implements IBaseService {
await copyPassively(from, to)
return
}
if (e.code === 'EPERM') {
throw new BaseServiceException({
type: 'migrationNoPermission',
source,
destination,
})
}
}
throw e
}
}
await this.app.migrateRoot(destination)
} catch (e) {
this.error(new AnyError('MigrateRootError', `Fail to migrate with rename ${source} -> ${destination} with unknown error`, { cause: e }))
await this.app.migrateRoot(source).catch(() => { })
throw e
}
await this.app.migrateRoot(destination)

this.app.relaunch()
this.app.quit()
Expand Down

0 comments on commit c3011a3

Please sign in to comment.