fix: prevent relocation to root directories (#6547)
* fix: prevent relocation to root directories * Update web-app/src/locales/zh-TW/settings.json Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
This commit is contained in:
parent
5adc0d9d46
commit
292941e1d0
@ -209,6 +209,8 @@
|
|||||||
"showInFileExplorer": "Show in File Explorer",
|
"showInFileExplorer": "Show in File Explorer",
|
||||||
"openContainingFolder": "Open Containing Folder",
|
"openContainingFolder": "Open Containing Folder",
|
||||||
"failedToRelocateDataFolder": "Failed to relocate data folder",
|
"failedToRelocateDataFolder": "Failed to relocate data folder",
|
||||||
|
"couldNotRelocateToRoot": "Cannot relocate data folder to root directory. Please choose another location.",
|
||||||
|
"couldNotResetRootDirectory": "Cannot reset data folder when it's set to a root directory. Please delete the data folder manually.",
|
||||||
"failedToRelocateDataFolderDesc": "Failed to relocate data folder. Please try again.",
|
"failedToRelocateDataFolderDesc": "Failed to relocate data folder. Please try again.",
|
||||||
"devVersion": "Development version detected",
|
"devVersion": "Development version detected",
|
||||||
"noUpdateAvailable": "You're running the latest version",
|
"noUpdateAvailable": "You're running the latest version",
|
||||||
|
|||||||
@ -203,6 +203,8 @@
|
|||||||
"showInFinder": "Tampilkan di Finder",
|
"showInFinder": "Tampilkan di Finder",
|
||||||
"showInFileExplorer": "Tampilkan di File Explorer",
|
"showInFileExplorer": "Tampilkan di File Explorer",
|
||||||
"openContainingFolder": "Buka Folder Induk",
|
"openContainingFolder": "Buka Folder Induk",
|
||||||
|
"couldNotRelocateToRoot": "Tidak dapat memindahkan folder data ke direktori root. Silakan pilih lokasi lain.",
|
||||||
|
"couldNotResetRootDirectory": "Tidak dapat mengatur ulang folder data saat diatur ke direktori root. Silakan hapus folder data secara manual.",
|
||||||
"failedToRelocateDataFolder": "Gagal memindahkan folder data",
|
"failedToRelocateDataFolder": "Gagal memindahkan folder data",
|
||||||
"failedToRelocateDataFolderDesc": "Gagal memindahkan folder data. Silakan coba lagi.",
|
"failedToRelocateDataFolderDesc": "Gagal memindahkan folder data. Silakan coba lagi.",
|
||||||
"devVersion": "Versi pengembangan terdeteksi",
|
"devVersion": "Versi pengembangan terdeteksi",
|
||||||
|
|||||||
@ -206,6 +206,8 @@
|
|||||||
"showInFinder": "Pokaż w Finderze",
|
"showInFinder": "Pokaż w Finderze",
|
||||||
"showInFileExplorer": "Pokaż w Explorerze",
|
"showInFileExplorer": "Pokaż w Explorerze",
|
||||||
"openContainingFolder": "Otwórz Katalog Nadrzędny",
|
"openContainingFolder": "Otwórz Katalog Nadrzędny",
|
||||||
|
"couldNotRelocateToRoot": "Nie można przenieść folderu danych do katalogu głównego. Proszę wybrać inną lokalizację.",
|
||||||
|
"couldNotResetRootDirectory": "Nie można zresetować folderu danych, gdy jest ustawiony na katalog główny. Proszę ręcznie usunąć folder danych.",
|
||||||
"failedToRelocateDataFolder": "Błąd zmiany katalogu danych",
|
"failedToRelocateDataFolder": "Błąd zmiany katalogu danych",
|
||||||
"failedToRelocateDataFolderDesc": "Nie udało się przenieść katalogu danych. Proszę spróbować później.",
|
"failedToRelocateDataFolderDesc": "Nie udało się przenieść katalogu danych. Proszę spróbować później.",
|
||||||
"devVersion": "Wykryto wersję deweloperską",
|
"devVersion": "Wykryto wersję deweloperską",
|
||||||
|
|||||||
@ -205,6 +205,8 @@
|
|||||||
"showInFinder": "Hiển thị trong Finder",
|
"showInFinder": "Hiển thị trong Finder",
|
||||||
"showInFileExplorer": "Hiển thị trong File Explorer",
|
"showInFileExplorer": "Hiển thị trong File Explorer",
|
||||||
"openContainingFolder": "Mở Thư mục Chứa",
|
"openContainingFolder": "Mở Thư mục Chứa",
|
||||||
|
"couldNotRelocateToRoot": "Không thể di chuyển thư mục dữ liệu đến thư mục gốc. Vui lòng chọn vị trí khác.",
|
||||||
|
"couldNotResetRootDirectory": "Không thể đặt lại thư mục dữ liệu khi nó được đặt thành thư mục gốc. Vui lòng xóa thư mục dữ liệu thủ công.",
|
||||||
"failedToRelocateDataFolder": "Không thể di chuyển thư mục dữ liệu",
|
"failedToRelocateDataFolder": "Không thể di chuyển thư mục dữ liệu",
|
||||||
"failedToRelocateDataFolderDesc": "Không thể di chuyển thư mục dữ liệu. Vui lòng thử lại.",
|
"failedToRelocateDataFolderDesc": "Không thể di chuyển thư mục dữ liệu. Vui lòng thử lại.",
|
||||||
"devVersion": "Đã phát hiện phiên bản phát triển",
|
"devVersion": "Đã phát hiện phiên bản phát triển",
|
||||||
|
|||||||
@ -205,6 +205,8 @@
|
|||||||
"showInFinder": "在 Finder 中显示",
|
"showInFinder": "在 Finder 中显示",
|
||||||
"showInFileExplorer": "在文件资源管理器中显示",
|
"showInFileExplorer": "在文件资源管理器中显示",
|
||||||
"openContainingFolder": "打开包含文件夹",
|
"openContainingFolder": "打开包含文件夹",
|
||||||
|
"couldNotRelocateToRoot": "无法将数据文件夹重新定位到根目录。请选择其他位置。",
|
||||||
|
"couldNotResetRootDirectory": "当数据文件夹设置为根目录时,无法重置。请手动删除数据文件夹。",
|
||||||
"failedToRelocateDataFolder": "无法重新定位数据文件夹",
|
"failedToRelocateDataFolder": "无法重新定位数据文件夹",
|
||||||
"failedToRelocateDataFolderDesc": "无法重新定位数据文件夹。请重试。",
|
"failedToRelocateDataFolderDesc": "无法重新定位数据文件夹。请重试。",
|
||||||
"devVersion": "检测到开发版本",
|
"devVersion": "检测到开发版本",
|
||||||
|
|||||||
@ -203,6 +203,8 @@
|
|||||||
"showInFinder": "在 Finder 中顯示",
|
"showInFinder": "在 Finder 中顯示",
|
||||||
"showInFileExplorer": "在檔案總管中顯示",
|
"showInFileExplorer": "在檔案總管中顯示",
|
||||||
"openContainingFolder": "打開包含資料夾",
|
"openContainingFolder": "打開包含資料夾",
|
||||||
|
"couldNotRelocateToRoot": "無法將資料夾重新定位到根目錄。請選擇其他位置。",
|
||||||
|
"couldNotResetRootDirectory": "當資料檔案夾設定為根目錄時,無法重置。請手動刪除資料檔案夾。",
|
||||||
"failedToRelocateDataFolder": "無法重新定位資料夾",
|
"failedToRelocateDataFolder": "無法重新定位資料夾",
|
||||||
"failedToRelocateDataFolderDesc": "無法重新定位資料夾。請重試。",
|
"failedToRelocateDataFolderDesc": "無法重新定位資料夾。請重試。",
|
||||||
"devVersion": "檢測到開發版本",
|
"devVersion": "檢測到開發版本",
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { useHardware } from '@/hooks/useHardware'
|
|||||||
import LanguageSwitcher from '@/containers/LanguageSwitcher'
|
import LanguageSwitcher from '@/containers/LanguageSwitcher'
|
||||||
import { PlatformFeatures } from '@/lib/platform/const'
|
import { PlatformFeatures } from '@/lib/platform/const'
|
||||||
import { PlatformFeature } from '@/lib/platform/types'
|
import { PlatformFeature } from '@/lib/platform/types'
|
||||||
|
import { isRootDir } from '@/utils/path'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export const Route = createFileRoute(route.settings.general as any)({
|
export const Route = createFileRoute(route.settings.general as any)({
|
||||||
@ -73,6 +74,11 @@ function General() {
|
|||||||
}, [serviceHub])
|
}, [serviceHub])
|
||||||
|
|
||||||
const resetApp = async () => {
|
const resetApp = async () => {
|
||||||
|
// Prevent resetting if data folder is root directory
|
||||||
|
if (isRootDir(janDataFolder ?? '/')) {
|
||||||
|
toast.error(t('settings:general.couldNotResetRootDirectory'))
|
||||||
|
return
|
||||||
|
}
|
||||||
pausePolling()
|
pausePolling()
|
||||||
// TODO: Loading indicator
|
// TODO: Loading indicator
|
||||||
await serviceHub.app().factoryReset()
|
await serviceHub.app().factoryReset()
|
||||||
@ -117,6 +123,9 @@ function General() {
|
|||||||
serviceHub.events().emit(SystemEvent.KILL_SIDECAR)
|
serviceHub.events().emit(SystemEvent.KILL_SIDECAR)
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
|
// Prevent relocating to root directory (e.g., C:\ or D:\ on Windows, / on Unix)
|
||||||
|
if (isRootDir(selectedNewPath))
|
||||||
|
throw new Error(t('settings:general.couldNotRelocateToRoot'))
|
||||||
await serviceHub.app().relocateJanDataFolder(selectedNewPath)
|
await serviceHub.app().relocateJanDataFolder(selectedNewPath)
|
||||||
setJanDataFolder(selectedNewPath)
|
setJanDataFolder(selectedNewPath)
|
||||||
// Only relaunch if relocation was successful
|
// Only relaunch if relocation was successful
|
||||||
|
|||||||
29
web-app/src/utils/path.ts
Normal file
29
web-app/src/utils/path.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Determines if the given path is a root directory.
|
||||||
|
*
|
||||||
|
* On Windows, this checks for drive roots such as `C:\` or `D:\`.
|
||||||
|
* On Mac/Linux, this checks if the path is `/`.
|
||||||
|
*
|
||||||
|
* @param selectedNewPath - The path to check.
|
||||||
|
* @returns `true` if the path is a root directory, otherwise `false`.
|
||||||
|
*/
|
||||||
|
export const isRootDir = (selectedNewPath: string) => {
|
||||||
|
// Windows root: C:\, D:\, etc.
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
return /^[a-zA-Z]:\\?$/.test(selectedNewPath)
|
||||||
|
}
|
||||||
|
// Linux/Mac root: /, /mnt, /media, etc.
|
||||||
|
const linuxRoots = [
|
||||||
|
'/',
|
||||||
|
'/mnt',
|
||||||
|
'/media',
|
||||||
|
'/boot',
|
||||||
|
'/home',
|
||||||
|
'/opt',
|
||||||
|
'/var',
|
||||||
|
'/usr',
|
||||||
|
]
|
||||||
|
const normalized =
|
||||||
|
selectedNewPath.replace(/\\/g, '/').replace(/\/+$/, '') || '/'
|
||||||
|
return linuxRoots.some((root) => normalized === root)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user