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

Fake os.open does not handle the O_DIRECTORY flag #974

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

Fake os.open does not handle the O_DIRECTORY flag #974

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

Comments

@vector-of-bool
Copy link

Describe the bug
The POSIX O_DIRECTORY open flag causes open() to mandate that the opened file is a directory. If the file is not a directory, it should fail with ENOTDIR. pyfakefs does not generate such an error, and later attempts to use the resulting fileno as a directory will raise errors.

How To Reproduce

def open_directory(filepath: Path, dirpath: Path):
    filepath.write_text("hey")
    with pytest.raises(NotADirectoryError):
        os.open(filepath, os.O_RDONLY | os.O_DIRECTORY)
    dirpath.mkdir(exist_ok=True)
    with pytest.raises(IsADirectoryError):
        os.open(dirpath, os.O_RDWR | os.O_DIRECTORY)

def test_realfs():
    open_directory(Path("file.txt"), Path("directory.d"))

def test_fakefs(fs):
    open_directory(Path("file.txt"), Path("directory.d"))

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
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