-
Notifications
You must be signed in to change notification settings - Fork 91
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
Inconsistent view on file/directory ownership via FakeOsModule and FakePathlibModule #678
Comments
Thanks! Ownership is implemented only very rudimentary in pyfakefs. Also, it would help to understand your use case better, e.g. what are you testing and what is failing - your example code has a couple of syntax errors, so I'm not exactly sure what you are doing there. |
Thanks for the quick response. Sorry for the syntax errors. I could not copy paste the running code easily so I quickly typed it over making a couple of mistakes along the way. In my case I want to test ownership of a file which does not match the process owner. The application is a backup/restore framework that normally executes under its own system user and operates on files owned by a different user. In version 4.5.0 this used to work. I used fake_filesystem.set_uid to set the user id. In the code under test (which uses pathlib) a file ownership test would fail or succeed based on the uid that was being set in the surrounding test case. Today I took some time to see why newer versions of pyfakefs were causing a failures. Based on the documentation I was expecting the old behaviour which corresponds with the uid/gid that is returned with the patched version of os.stat(). In other words the property that I was relying on is that given a filename 'test' I expect os.stat('test') to contain the same uid as the uid "associated with" fake_pathlib.Path('test'). In my full test setup I also patch pwd.getpwuid and pwd.getpwnam to control the mapping from uid to name. So I have no real need for synchronisation between real user IDs and fake ones. I simply make them up for the test. |
Ok, thank you for the explanation! If you patch these functions, this makes more sense to me, and I will see if I can understand and fix the problem. It just may take a while until I get to it. |
After having a second look (sorry it took me so long) I don't really understand why I implemented it the way it is. I think I did it that way because the fake filesystem is always created by the current user, and that way you have a valid user id, while setting some random user id to a file after creation may not be compatible with the real users, and All that said, using the default implementation (using |
- both methods now look up the real user/group name for the user/group id that is associated with the fake file - assumes a valid user and group id is set - closes pytest-dev#678
- both methods now look up the real user/group name for the user/group id that is associated with the fake file - assumes a valid user and group id is set - closes #678
…hods now look up the real user/group name for the user/group id that is associated with the fake file - assumes a valid user and group id is set - closes #678
Describe the bug
Since version 4.5.1 of pyfakefs there is an implementation of pathlib.Path.owner(), while previous version delate to the original pathlib implementation which uses os.stat. The new implementation assumes that the process owner is also the owner of the file. The result is an inconsistent view on ownership of the same file/directory depending on the method of obtaining the ownership data.
How To Reproduce
Your environment
The text was updated successfully, but these errors were encountered: