Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions specfile/specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(
if file is not None:
self._file = file
elif path is not None:
self._file = Path(path).open("r+", **self.ENCODING_ARGS)
self._file = Path(path).open("r", **self.ENCODING_ARGS)
elif content is not None:
self._file = StringIO(content)
else:
Expand Down Expand Up @@ -224,7 +224,7 @@ def _reopen_named_file(self) -> None:
if not self.path:
return
self._file.close()
self._file = self.path.open("r+", **self.ENCODING_ARGS)
self._file = self.path.open("r", **self.ENCODING_ARGS)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Changing the file opening mode to "r" in _reopen_named_file() will cause the save() method to fail. The save() method (lines 294-306) calls _reopen_named_file() and then attempts to truncate and write to the file handle. Since the file is now opened in read-only mode, these operations will raise an io.UnsupportedOperation error.

To resolve this, _reopen_named_file() should be updated to accept a mode parameter (defaulting to "r"), and save() should be updated to call it with mode="r+". Since save() is not currently part of this diff, you should include it in the pull request to apply the necessary changes.


@property
def path(self) -> Optional[Path]:
Expand All @@ -239,7 +239,7 @@ def path(self, value: Union[Path, str]) -> None:
path = Path(value)
if path == self.path:
return
self._file = path.open("r+", **self.ENCODING_ARGS)
self._file = path.open("r", **self.ENCODING_ARGS)

@property
def sourcedir(self) -> Path:
Expand Down
Loading