Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions __tests__/files/file.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()
}
}

}