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
mhlib fails on Btrfs filesystem (test_mhlib failure) #52007
Comments
Btrfs does not maintain a link count for directories (MacOS does the same I think). That confuses mhlib.py because it uses os.stat().st_nlinks as an optimization. The attached patch removes the optimization and make test_mhlib pass on Btrfs (and probably HFS+) filesystems. |
Please can you write a test for your patch? |
The documentation mentions that mhlib is deprecated and mailbox should be used instead. Is there any point in trying to fix it? |
On Sat, Jan 23, 2010 at 06:09:33PM +0000, Antoine Pitrou wrote:
It looks like Btrfs will eventually conform to traditional st_nlink I can imagine that removing the optimization can make mhlib much Neil |
That wasn't really my question. What I ask is: since mhlib is |
On Sun, Jan 24, 2010 at 01:25:18AM +0000, Antoine Pitrou wrote:
Sorry, I don't understand what you are proposing. Do you mean we
No, it doesn't have that optimization. Neil |
Hmm, you are right. From a quick glance, the patch looks ok. I assume you've checked it doesn't break anything else :) |
Since mhlib has gone from py3k is there any interest in applying this to 2.6 or 2.7, given that there's been no response to msg98232? |
Closing this bug. I don't think it makes sense to change the mhlib module in bugfix release. My patch is fairly simple but not simple enough to make me feel comfortable. |
The new buildbot edelsohn-sles-z is red from its setting at 19 Aug 2015. test_mhlib is the only failed test. http://buildbot.python.org/all/builders/s390x%20SLES%202.7/builds/114/steps/test/logs/stdio Traceback (most recent call last):
File "/home/dje/cpython-buildarea/2.7.edelsohn-sles-z/build/Lib/test/test_mhlib.py", line 185, in test_listfolders
eq(folders, tfolders)
AssertionError: Lists differ: [] != ['deep', 'deep/f1', 'deep/f2',... Second list contains 6 additional elements.
---------------------------------------------------------------------- I think we should fix this issue. Proposed patch adds a test that we can use nlinks for count a number of subdirectories. |
Here is even simpler and more reliable patch. It works even if the subfolder is a symlink to the directory on the filesystem that doesn't support links counting for directories. |
Sure, why not. Having buildbots be green is good, and I doubt anyone is using mhlib any more even in python2. And if they are the chances this will break something seems extremely small. |
New changeset 37431d9abbcd by Serhiy Storchaka in branch '2.7': |
The test now is passed. |
I don't see how that patch can be correct. The logic is now if the directory has two links inside it then skip it. The filesystems that don't count '.' and '..' will have zero links when empty and will have two links when two real files exist in them. I think my original patch is safer. |
AFAIK the filesystem either counts directory references, in this case st_nlink >= 2, and st_nlink == 2 only for empty directory. The exception is a root directory, but it is not relevant. Or it doesn't count directory references, in this case st_nlink == 1. |
So what happens for the filesystems that doesn't count '.' and '..'? It looks to me like if there are exactly two messages in a folder then the revised code will return [] (i.e. it will think the folder is empty). Probably we should revise the unit test to make a folder with two messages. |
st_nlink is not related to the number of messages in a folder. It is a number of hard links. If the filesystem supports hard links counting for directories, every directory (except /) has at least two links: one from its parent directory, and one from itself (via "."). Every subdirectory adds yet one hard link via "..". Non-directory files don't create hard links. Typical mail folder can contain thousands of messages and none or only a few subfolders. Subfolders (if there are any) usually are created before messages and hence encountered first in directory listing. Hereby the optimization can have significant effect. If there is a real case when st_nlink != 1 and is less then a number of subdirectories + 2, we should consider removing the optimization. |
Okay, feel free to close this bug. I had heard that HFS+ counts files but I don't have a way to verify that. |
Yes, what I read, HFS+ counts files. st_ntlink is a number of files and directories + 2 (perhaps for fake "." and ".."). This value never less than 2 + number_of_subdirectories, hence the code should work. Just an optimization has no any effect (as well as on FS where st_ntlink == 1). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: