Skip to content
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

st_ctime/st_atime/st_mtime differences in behaviour compared to linux #435

Closed
simonfagerholm opened this issue Oct 1, 2018 · 5 comments · Fixed by #439
Closed

st_ctime/st_atime/st_mtime differences in behaviour compared to linux #435

simonfagerholm opened this issue Oct 1, 2018 · 5 comments · Fixed by #439
Assignees
Labels

Comments

@simonfagerholm
Copy link

simonfagerholm commented Oct 1, 2018

Hi, I might have found a problem depending on the expected behaviour.
I noticed that the times st_ctime/st_atime/st_mtime are behaving differently in regard to when the times are updated and if they are updated.
I created two testfiles that run the same sequences on the real fs and on pyfakefs and checks it, see travis build:
https://travis-ci.org/simonfagerholm/pyfakefs/builds/434572170
The test files are fake_stat_time_test.py and real_stat_time_test.py

On linux the real_stat_time_test.py passes all tests (confirming that the expected result corresponds to linux fs) but many fail on pyfakefs. However, on mac os the real_stat_time_test.py also fails a few times so linux and mac behaves differently.

How is pyfakefs supposed to work?

@mrbean-bremen
Copy link
Member

Hm. good question. I would say it is supposed to roughly work like the real systems, but as these behave differently (Windows has it's own quirks, too), this is definitely not the case currently. As this has not been requested so far, probably nobody has really used this in a test.
While I doubt that we will have complete duplication of the real behavior, we could certainly make it behave better. Your tests suite seems like a realy good start for this - thanks for that! I will have a closer look later.

@mrbean-bremen mrbean-bremen self-assigned this Oct 3, 2018
@mrbean-bremen
Copy link
Member

The different behavior under MacOS is most likely due to the low time stamp resolution of 1 second in HFS+. In NTFS and most Linux file systems the resolution is much higher (I think we can ignore FAT/FAT32, where the resolution is 2 s for mtime and 1 day for atime). I assume that MacOS behaves the same way as Linux, just with a worse time stamp resolution.

@simonfagerholm
Copy link
Author

I think you are correct, I tested changing the sleep time (after each read of stat) to 2 s and reran the tests. Now both Linux and MacOS passed the real_stat_time_test.py.
fake_stat_time_test.py still fail on both

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Oct 6, 2018

Yes, I did the same (well, almost - I used 1.1 s), you can check it here.
I adapted the tests to also work under Windows where the behavior is slightly different, and adapted them a bit to our test infrastructure. I disabled the tests against pyfakefs to test the real file system first, but will enable them as soon as I fix pyfakefs.
I also think that it makes sense to add a timestamp resolution to the file system, that will default to the value for NTFS under Windows, for ext4 under Linux and HFS+ under MacOS, but can be set by the user to match other file systems (ext3 and before for example also had a resolution of 1s).

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Oct 7, 2018
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Oct 8, 2018
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Oct 8, 2018
mrbean-bremen added a commit that referenced this issue Oct 8, 2018
@mrbean-bremen
Copy link
Member

@simonfagerholm - thanks for the report and the tests - this has been quite helpful!
I will try to add the time resolution stuff some time later.

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

Successfully merging a pull request may close this issue.

2 participants