Skip to content

Commit 4dc8615

Browse files
committed
Correctly handle full disk after append
- do not update flush position before disk size is checked - see #660
1 parent 9f486bc commit 4dc8615

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

CHANGES.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ This is a bugfix release.
5757
* handle `pathlib.Path.owner()` and `pathlib.Path.group` by returning
5858
the current user/group name (see [#629](../../issues/629))
5959
* fixed handling of `use_known_patches=False` (could cause an exception)
60+
* removed Python 3.5 from metadata to disable installation for that version
61+
(see [#615](../../issues/615))
6062

6163
### Infrastructure
6264
* added test dependency check (see [#608](../../issues/608))
@@ -66,6 +68,9 @@ This is a bugfix release.
6668
## [Version 4.5.0](https://pypi.python.org/pypi/pyfakefs/4.5.0) (2021-06-04)
6769
Adds some support for Python 3.10 and basic type checking.
6870

71+
_Note_: This version has been yanked from PyPi as it erroneously allowed
72+
installation under Python 3.5.
73+
6974
### New Features
7075
* added support for some Python 3.10 features:
7176
* new method `pathlib.Path.hardlink_to`
@@ -232,8 +237,8 @@ This is a bugfix release that fixes a regression issue.
232237
## [Version 4.0.2](https://pypi.python.org/pypi/pyfakefs/4.0.2) (2020-03-04)
233238

234239
This as a patch release that only builds for Python 3. Note that
235-
versions 4.0.0 and 4.0.1 will be removed from PyPi to not to be able to
236-
install them under Python 2.
240+
versions 4.0.0 and 4.0.1 will be removed from PyPi to disable
241+
installing them under Python 2.
237242

238243
#### Fixes
239244
* Do not build for Python 2 (see [#524](../../issues/524))
@@ -242,14 +247,19 @@ install them under Python 2.
242247

243248
This as a bug fix release for a regression bug.
244249

250+
_Note_: This version has been yanked from PyPi as it erroneously allowed
251+
installation under Python 2. This has been fixed in version 4.0.2.
252+
245253
#### Fixes
246254
* Avoid exception if using `flask-restx` (see [#523](../../issues/523))
247255

248256
## [Version 4.0.0](https://pypi.python.org/pypi/pyfakefs/4.0.0) (2020-03-03)
257+
pyfakefs 4.0.0 drops support for Python 2.7. If you still need
258+
Python 2.7, you can continue to use pyfakefs 3.7.x.
259+
260+
_Note_: This version has been yanked from PyPi as it erroneously allowed
261+
installation under Python 2. This has been fixed in version 4.0.2.
249262

250-
* pyfakefs 4.0.0 drops support for Python 2.7. If you still need
251-
Python 2.7, you can continue to use pyfakefs 3.7.x.
252-
253263
#### Changes
254264
* Removed Python 2.7 and 3.4 support (see [#492](../../issues/492))
255265

pyfakefs/fake_filesystem.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ def set_contents(self, contents: AnyStr,
455455
if they are a unicode string.
456456
If not given, the locale preferred encoding is used.
457457
458+
Returns:
459+
True if the contents have been changed.
460+
458461
Raises:
459462
OSError: if `st_size` is not a non-negative integer,
460463
or if it exceeds the available file system space.
@@ -5049,8 +5052,9 @@ def flush(self) -> None:
50495052
self._set_stream_contents(contents)
50505053
else:
50515054
self._io.flush()
5055+
changed = self.file_object.set_contents(contents, self._encoding)
50525056
self.update_flush_pos()
5053-
if self.file_object.set_contents(contents, self._encoding):
5057+
if changed:
50545058
if self._filesystem.is_windows_fs:
50555059
self._changed = True
50565060
else:

pyfakefs/tests/fake_filesystem_test.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ def test_disk_size_on_auto_mounted_drive_on_directory_creation(self):
17901790
self.filesystem.create_file('d:!foo!bar!baz', st_size=100)
17911791
self.filesystem.create_file('d:!foo!baz', st_size=100)
17921792
self.filesystem.set_disk_usage(total_size=1000, path='d:')
1793-
self.assertEqual(self.filesystem.get_disk_usage('d:!foo').free, 800)
1793+
self.assertEqual(800, self.filesystem.get_disk_usage('d:!foo').free)
17941794

17951795
def test_copying_preserves_byte_contents(self):
17961796
source_file = self.filesystem.create_file('foo', contents=b'somebytes')
@@ -1802,16 +1802,30 @@ def test_diskusage_after_open_write(self):
18021802
with self.open('bar.txt', 'w') as f:
18031803
f.write('a' * 60)
18041804
f.flush()
1805-
self.assertEqual(self.filesystem.get_disk_usage()[1], 60)
1805+
self.assertEqual(60, self.filesystem.get_disk_usage()[1])
18061806

18071807
def test_disk_full_after_reopened(self):
18081808
with self.open('bar.txt', 'w') as f:
18091809
f.write('a' * 60)
18101810
with self.open('bar.txt') as f:
1811-
self.assertEqual(f.read(), 'a' * 60)
1811+
self.assertEqual('a' * 60, f.read())
18121812
with self.raises_os_error(errno.ENOSPC):
18131813
with self.open('bar.txt', 'w') as f:
18141814
f.write('b' * 110)
1815+
with self.raises_os_error(errno.ENOSPC):
1816+
f.flush()
1817+
1818+
def test_disk_full_append(self):
1819+
file_path = 'bar.txt'
1820+
with self.open(file_path, 'w') as f:
1821+
f.write('a' * 60)
1822+
with self.open(file_path) as f:
1823+
self.assertEqual('a' * 60, f.read())
1824+
with self.raises_os_error(errno.ENOSPC):
1825+
with self.open(file_path, 'a') as f:
1826+
f.write('b' * 41)
1827+
with self.raises_os_error(errno.ENOSPC):
1828+
f.flush()
18151829

18161830
def test_disk_full_after_reopened_rplus_seek(self):
18171831
with self.open('bar.txt', 'w') as f:
@@ -1822,6 +1836,8 @@ def test_disk_full_after_reopened_rplus_seek(self):
18221836
with self.open('bar.txt', 'r+') as f:
18231837
f.seek(50)
18241838
f.write('b' * 60)
1839+
with self.raises_os_error(errno.ENOSPC):
1840+
f.flush()
18251841

18261842

18271843
class MountPointTest(TestCase):

0 commit comments

Comments
 (0)