Repository navigation
Conversation
`backups.file_path` held the absolute archive path, unlike every other
stored file reference. A backup restored on another machine therefore
pointed under the previous user's home directory, and the row leaked the
local filesystem layout.
Store `backup-${id}.tar.gz` instead and resolve it against
`resolveTargetDirectory()` on read through a single `archivePathFor`
helper. Applying `path.basename` keeps legacy absolute rows working.
Fixes Open-Glassbeetle#330
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
backups.file_pathstores the absolute archive path(
…/backups/backup-<id>.tar.gz), while every other stored file reference in thedatabase is a relative one (
pictures/…,project-images/…) as required by theFileStorageServicecontract. Restoring a backup archive on another machineleaves every historical row pointing into the old user's home directory, and the
row leaks the local filesystem layout.
Root cause
createBackupinsertsfinalArchivePath— built fromresolveTargetDirectory()— into
backups.file_path, anddeleteBackupplusmapRowToResponse'sexistsSyncprobe read that column back as an absolute path.Fix
backup-${id}.tar.gzinfile_path.archivePathFor(row)that joinsresolveTargetDirectory()with
path.basename(row.file_path), and use it indeleteBackupand inmapRowToResponse'sexistsSyncprobe.path.basenameon read means rows written by the previous code keepresolving correctly; no schema migration needed.
FileStorageService: its containment check isrelative to the storage root, and a backup can legitimately be written to a
user-chosen directory.
One behaviour note: the target directory stays configurable. If a user changes
backup_policy.target_directoryand later changes it back, a stored filenameresolves against whatever is configured now;
isAvailablereports the truth viaexistsSync. Storing an absolute path did not avoid that — it just faileddifferently.
Testing
npm run test -w @glassbeetle/api -- src/modules/application/backups/backups.service.spec.ts— 19 passed. New coverage: a freshcreateBackuprow stores a bare filename; a legacy absolute row still resolves and deletes; existing delete/presence tests now resolve through the target directory.npm run test:e2e -w @glassbeetle/api -- test/backups.e2e-spec.ts— 14 passed.npm run lint -w @glassbeetle/api— 0 warnings, 0 errors.npm run build -w @glassbeetle/api— passes.Fixes #330