From 943e89ba7f825947d8f751b3e128e850f48b42c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=AD=8F=E6=B4=AA?= Date: Wed, 28 Jan 2026 15:44:12 +0800 Subject: [PATCH] fix: Remove root directory error --- __tests__/ut/commands/modelService_test.ts | 6 +++--- src/subCommands/model/model.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/__tests__/ut/commands/modelService_test.ts b/__tests__/ut/commands/modelService_test.ts index bc4aa73..2750e60 100644 --- a/__tests__/ut/commands/modelService_test.ts +++ b/__tests__/ut/commands/modelService_test.ts @@ -329,7 +329,7 @@ describe('ModelService', () => { it('should successfully remove model', async () => { const name = 'test-project$test-env$test-function'; const params = { - nasMountPoints: [{ mountDir: '/mnt/test' }], + nasMountPoints: [{ mountDir: '/mnt/test', serverAddr: 'xxxxx:/test' }], ossMountPoints: [], role: 'acs:ram::123456789:role/aliyundevsdefaultrole', region: 'cn-hangzhou', @@ -350,7 +350,7 @@ describe('ModelService', () => { it('should handle remove error', async () => { const name = 'test-project$test-env$test-function'; const params = { - nasMountPoints: [{ mountDir: '/mnt/test' }], + nasMountPoints: [{ mountDir: '/mnt/test', serverAddr: 'xxxxx:/test' }], ossMountPoints: [], role: 'acs:ram::123456789:role/aliyundevsdefaultrole', region: 'cn-hangzhou', @@ -374,7 +374,7 @@ describe('ModelService', () => { it('should handle remove error with NoSuchFileError', async () => { const name = 'test-project$test-env$test-function'; const params = { - nasMountPoints: [{ mountDir: '/mnt/test' }], + nasMountPoints: [{ mountDir: '/mnt/test', serverAddr: 'xxxxx:/test' }], ossMountPoints: [], role: 'acs:ram::123456789:role/aliyundevsdefaultrole', region: 'cn-hangzhou', diff --git a/src/subCommands/model/model.ts b/src/subCommands/model/model.ts index e4106dd..77dec5b 100644 --- a/src/subCommands/model/model.ts +++ b/src/subCommands/model/model.ts @@ -107,6 +107,23 @@ export class ModelService { const processedOssMountPoints = extractOssMountDir(ossMountPoints); + if ( + storage === 'oss' && + processedOssMountPoints[0] && + (!processedOssMountPoints[0].bucketPath || processedOssMountPoints[0].bucketPath === '/') + ) { + throw new Error( + 'The current deleted directory is the OSS root directory. To delete the current model, please go to the OSS console to delete the model.', + ); + } + + const nasPath = nasMountPoints[0]?.serverAddr?.split(':')[1]; + + if (storage === 'nas' && nasMountPoints[0] && nasPath?.trim() === '/') { + throw new Error( + 'The current deleted directory is the NAS root directory. To delete the current model, please go to the NAS console to delete the model.', + ); + } const fileManagerRmRequest = new $Dev20230714.FileManagerRmRequest({ filepath: storage === 'nas' ? nasMountPoints[0]?.mountDir : processedOssMountPoints[0]?.mountDir,