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

Size limits (OSError Errno 28) causing content do disappear #548

Closed
couling opened this issue Aug 25, 2020 · 2 comments
Closed

Size limits (OSError Errno 28) causing content do disappear #548

couling opened this issue Aug 25, 2020 · 2 comments
Labels

Comments

@couling
Copy link

couling commented Aug 25, 2020

Size limits (OSError Errno 28) causing content do disappear. Content that has been flushed to the file disappears after a further failed write.

The following test should pass:

def test_fake_fs(fs):
    fs.set_disk_usage(100)  # sets the file system size in bytes
    os.makedirs("/foo")
    with open('/foo/bar.txt', 'wb') as f:
        f.write(b'a' * 50)
        f.flush()
        # By this point 50 bytes must be "committed" into the file whatever happens next.
        with open('/foo/bar.txt', "rb") as r:
            x = r.read()
            # Yes, it's there!
            assert x.startswith(b'a' * 50)
        with pytest.raises(OSError):
            f.write(b'b' * 200)
            f.flush()
        with open('/foo/bar.txt', "rb") as r:
            x = r.read()
            # Wait, where did it go
            assert x.startswith(b'a' * 50)
        # Because of the above assertion failure, the truncate never happens
        f.truncate(50)
    # The implicit close causes another OSError because of the missing truncate().

My enviroment

(.venv) $ python -c "import platform; print(platform.platform())"
Linux-5.4.0-42-generic-x86_64-with-glibc2.29
(.venv) $ python -c "import sys; print('Python', sys.version)"
Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
(.venv) $ python -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs', __version__)"
pyfakefs 4.1.0
(.venv) $ 
@couling
Copy link
Author

couling commented Aug 25, 2020

Apologies, I've just spotted the above test should fail but for different reasons. With buffered file access, the truncate() would also fail. But the above assertion failure is still wrong. There's no way that the file should randomly blank like that.

@couling couling changed the title Flush doesn't seem to have any proper effect. Size limits (OSError Errno 28) causing content do disappear Aug 25, 2020
@mrbean-bremen
Copy link
Member

Please check with master - should be fixed now.

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

No branches or pull requests

2 participants