Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(backend:files): preserve external-root paths in trash
johaven48b5118b52ef
diff --git a/backend/src/applications/files/services/files-manager.service.spec.ts b/backend/src/applications/files/services/files-manager.service.spec.tsindex dfc3c107..066e4780 100644--- a/backend/src/applications/files/services/files-manager.service.spec.ts+++ b/backend/src/applications/files/services/files-manager.service.spec.ts@@ -1374,7 +1374,7 @@ describe(FilesManager.name, () => {expect(emitSpy).toHaveBeenCalledWith('event', { user, space, action: ACTION.DELETE, rPath: trashFile })})- it('should move an external-root db entry into the canonical space-trash scope and preserve a collision', async () => {+ it('should namespace an external-root entry in the space trash and preserve a collision', async () => {const sourceDb = {ownerId: null,spaceId: 11,@@ -1384,16 +1384,18 @@ describe(FilesManager.name, () => {inTrash: false}const trashDbScope = { ownerId: null, spaceId: 11, spaceExternalRootId: null, shareExternalId: null, inTrash: true }- const trashDb = { ...trashDbScope, path: sourceDb.path }+ const trashDb = { ...trashDbScope, path: 'archive/documents/report.txt' }const space = makeSpace({id: 11,alias: 'project',+ inFilesRepository: true,inPersonalSpace: false,realPath: '/mnt/archive/documents/report.txt',+ root: { id: 22, alias: 'archive', externalPath: '/mnt/archive' },dbFile: sourceDb})- const trashFile = '/data/spaces/project/trash/documents/report.txt'- const renamedTrashFile = '/data/spaces/project/trash/documents/report-2026.txt'+ const trashFile = '/data/spaces/project/trash/archive/documents/report.txt'+ const renamedTrashFile = '/data/spaces/project/trash/archive/documents/report-2026.txt'vi.mocked(spacesPathUtils.trashTargetFromSpace).mockReturnValueOnce({dbScope: trashDbScope,mode: 'trash',@@ -1407,7 +1409,7 @@ describe(FilesManager.name, () => {expect(filesUtils.moveFiles).toHaveBeenNthCalledWith(1, trashFile, renamedTrashFile)expect(filesUtils.moveFiles).toHaveBeenNthCalledWith(2, space.realPath, trashFile, true)- expect(filesQueries.moveFiles).toHaveBeenNthCalledWith(1, trashDb, { ...trashDbScope, path: 'documents/report-2026.txt' }, false)+ expect(filesQueries.moveFiles).toHaveBeenNthCalledWith(1, trashDb, { ...trashDbScope, path: 'archive/documents/report-2026.txt' }, false)expect(filesQueries.moveFiles).toHaveBeenNthCalledWith(2, sourceDb, trashDb, false)expect(filesQueries.deleteFiles).not.toHaveBeenCalled()})diff --git a/backend/src/applications/files/services/files-manager.service.ts b/backend/src/applications/files/services/files-manager.service.tsindex cf3dbce3..a1e0d82b 100644--- a/backend/src/applications/files/services/files-manager.service.ts+++ b/backend/src/applications/files/services/files-manager.service.ts@@ -14,7 +14,7 @@ import { SPACE_OPERATION } from '../../spaces/constants/spaces'import { FastifySpaceRequest } from '../../spaces/interfaces/space-request.interface'import { SpaceEnv } from '../../spaces/models/space-env.model'import { SpacesManager } from '../../spaces/services/spaces-manager.service'-import { temporaryRootFromSpace, trashTargetFromSpace } from '../../spaces/utils/paths'+import { temporaryRootFromSpace, trashRelativePathFromSpace, trashTargetFromSpace } from '../../spaces/utils/paths'import { canAccessToSpace, haveSpaceEnvPermissions } from '../../spaces/utils/permissions'import { UserModel } from '../../users/models/user.model'import { DEPTH, LOCK_DEPTH } from '../../webdav/constants/webdav'@@ -580,10 +580,10 @@ export class FilesManager {throw new FileError(HttpStatus.INTERNAL_SERVER_ERROR, 'Unable to resolve trash target')}if (trashTarget.mode === 'trash') {- let destinationDbFile: FileDBProps = { ...trashTarget.dbScope, path: space.dbFile.path }- const name = fileName(space.realPath)- const trashDir = path.join(trashTarget.path, dirName(space.dbFile.path))- let trashFile = path.join(trashDir, name)+ const trashRelativePath = trashRelativePathFromSpace(space)+ let destinationDbFile: FileDBProps = { ...trashTarget.dbScope, path: trashRelativePath }+ const trashDir = path.join(trashTarget.path, dirName(trashRelativePath))+ let trashFile = path.join(trashDir, fileName(space.realPath))if (!(await isPathExists(trashDir))) {await makeDir(trashDir, true)}diff --git a/backend/src/applications/files/services/tasks/files-tasks-manager.service.ts b/backend/src/applications/files/services/tasks/files-tasks-manager.service.tsindex 08581917..209de906 100644--- a/backend/src/applications/files/services/tasks/files-tasks-manager.service.ts+++ b/backend/src/applications/files/services/tasks/files-tasks-manager.service.ts@@ -7,7 +7,7 @@ import { currentTimeStamp } from '../../../../common/shared'import { Cache } from '../../../../infrastructure/cache/cache.service'import { SpaceEnv } from '../../../spaces/models/space-env.model'import { SpacesManager } from '../../../spaces/services/spaces-manager.service'-import { trashTargetFromSpace } from '../../../spaces/utils/paths'+import { trashRelativePathFromSpace, trashTargetFromSpace } from '../../../spaces/utils/paths'import { UserModel } from '../../../users/models/user.model'import { CACHE_TASK_CANCEL_PREFIX, CACHE_TASK_PREFIX, CACHE_TASK_TTL } from '../../constants/cache'import { FILE_OPERATION } from '../../constants/operations'@@ -24,7 +24,6 @@ import { FilesTasksWatcher } from './files-tasks-watcher.service'@Injectable()export class FilesTasksManager implements OnModuleDestroy {- // Task cache key: `ftask-${userId}-${taskId}`.private readonly logger = new Logger(FilesTasksManager.name)private readonly watchInterval = 1000private tasksCancellationWatcher: Record<string, NodeJS.Timeout> = {}@@ -281,7 +280,7 @@ export class FilesTasksManager implements OnModuleDestroy {if (type === FILE_OPERATION.DELETE && !space.inTrashRepository) {const trashTarget = trashTargetFromSpace(user, space)if (trashTarget?.mode === 'trash') {- return path.join(trashTarget.path, dirName(space.dbFile.path), fileName(space.realPath))+ return path.join(trashTarget.path, dirName(trashRelativePathFromSpace(space)), fileName(space.realPath))}}} catch {diff --git a/backend/src/applications/spaces/utils/paths.ts b/backend/src/applications/spaces/utils/paths.tsindex 9becb7f3..d1b6f1c6 100644--- a/backend/src/applications/spaces/utils/paths.ts+++ b/backend/src/applications/spaces/utils/paths.ts@@ -131,6 +131,13 @@ export function trashTargetFromSpace(user: UserModel, space: SpaceEnv): TrashTarreturn null}+export function trashRelativePathFromSpace(space: SpaceEnv): string {+ if (space.inFilesRepository && space.root?.externalPath) {+ return path.join(space.root.alias, space.dbFile.path)+ }+ return space.dbFile.path+}+export function temporaryRootFromStorage(storageRoot: string, userId: number): string {if (!Number.isSafeInteger(userId) || userId <= 0) {throw new FileError(HttpStatus.BAD_REQUEST, 'Invalid temporary-file owner')