Skip to content

Commit

Permalink
Fix #21: FatIO: don't flush files on close if not open for writing
Browse files Browse the repository at this point in the history
Otherwise, you can never close a file on a read-only file system.
  • Loading branch information
abrasive authored and nathanhi committed Feb 27, 2022
1 parent a35586b commit 22eec9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -9,6 +9,14 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
Unreleased_
-----------

1.0.2_ - 2022-02-27
-------------------

Fixed
-----

* `PR #23 <https://github.com/nathanhi/pyfatfs/pull/23>`_: Do not try to write FAT if filesystem has been opened read-only by `@abrasive <https://github.com/abrasive>`_

1.0.1_ - 2022-02-08
-------------------

Expand Down
3 changes: 2 additions & 1 deletion pyfatfs/FatIO.py
Expand Up @@ -112,7 +112,8 @@ def seekable(self) -> bool:
def close(self) -> None:
"""Close open file handles assuming lock handle."""
self.seek(0)
self.fs.flush_fat()
if self.mode.writing:
self.fs.flush_fat()
super().close()

def readable(self) -> bool:
Expand Down

0 comments on commit 22eec9b

Please sign in to comment.