FIX: Use st_birthtime for 'created' field in LocalFileSystem.info() #1883
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
Currently, the
LocalFileSystem.info()method returnsos.stat_result.st_ctime(the inode change time) for the'created'field in its output dictionary. On modern Unix-like systems (including Linux with newer filesystems like ext4, and macOS) that support it, this is incorrect and can be misleading. These systems provide a more accuratest_birthtimeattribute that reflects the true creation time of a file.For example, modifying a file's permissions will update its
ctime, making the file appear to have been "created" more recently than it actually was, which is counterintuitive and can cause issues for applications relying on accurate creation timestamps.Solution:
This patch modifies the
LocalFileSystem.info()method to provide a more accurate'created'timestamp while maintaining backward compatibility.The new logic is as follows:
It checks if the
os.stat_resultobject has thest_birthtimeattribute.If
st_birthtimeexists, its value is used for the'created'field.If
st_birthtimedoes not exist (on older filesystems or operating systems), the implementation gracefully falls back to using the existingst_ctimevalue.This ensures that users on supported systems get the most accurate creation time possible without breaking compatibility for others.
Benefits:
Increased Accuracy: Provides the true file creation time on modern Linux, macOS, and other systems that support
birthtime.Improved User Experience: The
'created'field now behaves as users would expect, aligning with the "Birth" time seen in tools likestat.Backward Compatible: The fallback to
ctimeensures no functionality is lost on systems wherebirthtimeis not available.