Skip to content

FIX: Use st_birthtime for 'created' field in LocalFileSystem.info() #1883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025

Conversation

clang-viqi
Copy link
Contributor

Problem:

Currently, the LocalFileSystem.info() method returns os.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 accurate st_birthtime attribute 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:

  1. It checks if the os.stat_result object has the st_birthtime attribute.

  2. If st_birthtime exists, its value is used for the 'created' field.

  3. If st_birthtime does not exist (on older filesystems or operating systems), the implementation gracefully falls back to using the existing st_ctime value.

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 like stat.

  • Backward Compatible: The fallback to ctime ensures no functionality is lost on systems where birthtime is not available.

@martindurant
Copy link
Member

Since you have no github presence, this is your very first contribution and your description is rather verbose ... can you confirm you are real and say a little about yourself @clang-viqi ?

@clang-viqi
Copy link
Contributor Author

@martindurant Sure. I am indeed real and I am with ViQi, Inc., a company developing AI based image analytics & assays for the life science industry. We are evaluating fsspec as a means to access our backend stores.

@martindurant martindurant merged commit b669a80 into fsspec:master Jul 3, 2025
10 checks passed
@martindurant
Copy link
Member

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants