Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not update mtime if not already defined #709

Merged
merged 1 commit into from Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions __tests__/files/file.spec.ts
Expand Up @@ -223,4 +223,21 @@ describe('Altering attributes updates mtime', () => {
expect(file.mtime?.getDate()).toBe(new Date().getDate())
expect(file.attributes.test).toBeUndefined()
})

test('mtime is NOT updated if not initially defined', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma',
mime: 'image/jpeg',
owner: 'emma',
attributes: {
test: true,
},
})
expect(file.attributes.test).toBe(true)
delete file.attributes.test

// Check that mtime has been updated
expect(file.mtime).toBeUndefined()
expect(file.attributes.test).toBeUndefined()
})
})
15 changes: 12 additions & 3 deletions lib/files/node.ts
Expand Up @@ -40,13 +40,13 @@ export abstract class Node {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
set: (target: Attribute, prop: string, value: any): any => {
// Edit modification time
this._data.mtime = new Date()
this.updateMtime()
// Apply original changes
return Reflect.set(target, prop, value)
},
deleteProperty: (target: Attribute, prop: string) => {
// Edit modification time
this._data.mtime = new Date()
this.updateMtime()
// Apply original changes
return Reflect.deleteProperty(target, prop)
},
Expand Down Expand Up @@ -222,7 +222,7 @@ export abstract class Node {
move(destination: string) {
validateData({ ...this._data, source: destination }, this._knownDavService)
this._data.source = destination
this._data.mtime = new Date()
this.updateMtime()
}

/**
Expand All @@ -238,4 +238,13 @@ export abstract class Node {
this.move(dirname(this.source) + '/' + basename)
}

/**
* Update the mtime if exists.
*/
private updateMtime() {
if (this._data.mtime) {
this._data.mtime = new Date()
}
}

}