feat(server): restore modified at timestamp after upload, preserve when copying (#7010)

This commit is contained in:
Trevor Jex
2024-02-11 21:40:34 -07:00
committed by GitHub
parent 0c4df216d7
commit d7437d31d1
7 changed files with 49 additions and 3 deletions
@@ -42,4 +42,5 @@ export interface IStorageRepository {
copyFile(source: string, target: string): Promise<void>;
rename(source: string, target: string): Promise<void>;
watch(paths: string[], options: WatchOptions): ImmichWatcher;
utimes(filepath: string, atime: Date, mtime: Date): Promise<void>;
}
@@ -534,6 +534,12 @@ describe(StorageTemplateService.name, () => {
.mockResolvedValue({
size: 5000,
} as Stats);
when(storageMock.stat)
.calledWith(assetStub.image.originalPath)
.mockResolvedValue({
atime: new Date(),
mtime: new Date(),
} as Stats);
when(cryptoMock.hashFile).calledWith(newPath).mockResolvedValue(assetStub.image.checksum);
await sut.handleMigration();
@@ -542,6 +548,8 @@ describe(StorageTemplateService.name, () => {
expect(storageMock.rename).toHaveBeenCalledWith('/original/path.jpg', newPath);
expect(storageMock.copyFile).toHaveBeenCalledWith('/original/path.jpg', newPath);
expect(storageMock.stat).toHaveBeenCalledWith(newPath);
expect(storageMock.stat).toHaveBeenCalledWith(assetStub.image.originalPath);
expect(storageMock.utimes).toHaveBeenCalledWith(newPath, expect.any(Date), expect.any(Date));
expect(storageMock.unlink).toHaveBeenCalledWith(assetStub.image.originalPath);
expect(storageMock.unlink).toHaveBeenCalledTimes(1);
expect(assetMock.save).toHaveBeenCalledWith({
@@ -222,6 +222,9 @@ export class StorageCore {
return;
}
const { atime, mtime } = await this.repository.stat(move.oldPath);
await this.repository.utimes(newPath, atime, mtime);
try {
await this.repository.unlink(move.oldPath);
} catch (error: any) {