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

Patched os.open does not respect O_NOFOLLOW #972

Closed
vector-of-bool opened this issue Mar 11, 2024 · 1 comment · Fixed by #976
Closed

Patched os.open does not respect O_NOFOLLOW #972

vector-of-bool opened this issue Mar 11, 2024 · 1 comment · Fixed by #976

Comments

@vector-of-bool
Copy link

Describe the bug
POSIX open() supports an O_NOFOLLOW flag. If the file being opened is a symlink, open should fail with ELOOP. pyfakefs unconditionally follows symbolic links for open.

How To Reproduce

def open_nofollow(s: Path):
    s.unlink(missing_ok=True)
    s.symlink_to("nowhere")
    with pytest.raises(OSError) as exc:
        os.open(s, os.O_RDONLY | os.O_NOFOLLOW)
    assert exc.value.errno == errno.ELOOP

def test_realfs():
    open_nofollow(Path("file.txt"))

def test_fakefs(fs):
    open_nofollow(Path("file.txt"))

Your environment
Please run the following in the environment where the problem happened and
paste the output.

$ python -c "import platform; print(platform.platform())"
Linux-6.7.6-arch1-1-x86_64-with-glibc2.39
$ python -c "import sys; print('Python', sys.version)"
Python 3.11.7 (main, Jan 29 2024, 16:03:57) [GCC 13.2.1 20230801]
$ python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
pyfakefs 5.4.dev0
$ python -c "import pytest; print('pytest', pytest.__version__)"
pytest 7.2.0

Thanks for the quick turnaround on all these issues! My own project very heavily tests and uses low-level filesystem functionality that is less commonly seen, hence the barrage of issues.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Mar 11, 2024

That's ok, I appreciate that! It may take a bit until they all get resolved (my free time varies, and it takes longer for some issues), but this helps a lot.
A few years ago, we had somebody who used his own testing language to test pyfakefs, and he found a lot of mostly low-level issues (these are flagged with TSTL - there are 136 of them). This was very helpful too (though took also quite a bit of time to fix), and you are still far from that mark 😁

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

Successfully merging a pull request may close this issue.

2 participants