#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)
follow-up: 2 comment:1 by , 8 years ago
comment:2 by , 8 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 , 8 years ago
Component: | File uploads/storage → Documentation |
---|---|
Summary: | FileSystemStorage --- get_created_time method does not work on Unix → Document FileSystemStorage.get_created_time() limitation on Unix |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/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:6 by , 8 years ago
Patch needs improvement: | set |
---|
Perhaps
ctime
is good enough though, making the presumption that the inode attributes only change at creation time?