Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#27644 closed Cleanup/optimization (fixed)

Document FileSystemStorage.get_created_time() limitation on Unix

Reported by: Jonathan Verner Owned by: Ingo Klöcker
Component: Documentation Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The method get_created_time uses os.path.getctime which only returns the creation time on Windows. On Unix it returns the change time , i.e. the last time the inode attributes were modified (see http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python). The documentation says that

For storage systems unable to return the creation time this will raise NotImplementedError

so the correct behaviour would be, IHMO, to raise a NotImplementedError on Unix platforms. I am not sure whether the method is used anywhere---searching on github only came up with uses in tests, docs and the place where it is defined. Also, as noted by a commenter on the above stackoverflow question, it doesn't seem to be a useful value anyway:

Frankly, file creation time is usually fairly useless. When you open an existing file for write with mode "w", it's not replacing it, it just opens the existing file and truncates it. Even though the file contents are completely unrelated to whatever it had on creation, you'd still be told the file was "created" well before the current version. Conversely, editors that use atomic replace on save (original file is replaced by new work-in-progress temp file) would show a more recent creation date, even if you just deleted one character. Use the modification time, don't grub for creation time.

So it might make sense to remove the method altogether.

Change History (9)

comment:1 by Adam Johnson, 7 years ago

Perhaps ctime is good enough though, making the presumption that the inode attributes only change at creation time?

in reply to:  1 comment:2 by Jonathan Verner, 7 years ago

Replying to Adam Chainz:

Perhaps ctime is good enough though, making the presumption that the inode attributes only change at creation time?

Unfortunately, that is not the case: ctime changes at least as often as mtime does---updating the mtime changes inode attributes.

comment:3 by Tim Graham, 7 years ago

Component: File uploads/storageDocumentation
Summary: FileSystemStorage --- get_created_time method does not work on UnixDocument FileSystemStorage.get_created_time() limitation on Unix
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Accepting as a documentation clarification for now. I'm not sure if changing the method's implementation is worth it, but I think it would require a deprecation path. If you want to pursue that, please raise the idea on the DevelopersMailingList to get a consensus.

comment:4 by Ingo Klöcker, 7 years ago

Owner: changed from nobody to Ingo Klöcker
Status: newassigned

I'll look into this.

comment:5 by Ingo Klöcker, 7 years ago

Has patch: set

comment:6 by Tim Graham, 7 years ago

Patch needs improvement: set

comment:7 by Ingo Klöcker, 7 years ago

Patch needs improvement: unset

I've improved the patch.

comment:8 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In f3ac398d:

Fixed #27644 -- Doc'd FileSystemStorage.get_created_time().

comment:9 by Tim Graham <timograham@…>, 7 years ago

In 4678957b:

[1.11.x] Fixed #27644 -- Doc'd FileSystemStorage.get_created_time().

Backport of f3ac398dd595c43f551502c742b0b3cbe8440e50 from master

Note: See TracTickets for help on using tickets.
Back to Top