Skip to content

Commit

Permalink
Merge pull request #709 from nextcloud/fix/mtime
Browse files Browse the repository at this point in the history
fix: do not update mtime if not already defined
  • Loading branch information
susnux committed Jul 28, 2023
2 parents 4ef9865 + 8f072ec commit 4d4bf49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
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()
}
}

}

0 comments on commit 4d4bf49

Please sign in to comment.