Skip to content

Commit

Permalink
Fix TemporaryFileSwap bug when file_path is a Path
Browse files Browse the repository at this point in the history
This fixes the regression introduced in 9e86053 (gitpython-developers#1770) where the
file_path argument to TemporaryFileSwap.__init__ could no longer be
a Path object.

The change also makes this truer to the code from before gitpython-developers#1770,
still without the race condition fixed there, in that str was
called on file_path then as well. However, it is not clear that
this is a good thing, because this is not an idiomatic use of
mkstemp. The reason the `prefix` cannot be a Path is that it is
expected to be a filename prefix, with leading directories given in
the `dir` argument.
  • Loading branch information
EliahKagan committed Dec 21, 2023
1 parent 487a4fd commit 1ddf953
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion git/index/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TemporaryFileSwap:

def __init__(self, file_path: PathLike) -> None:
self.file_path = file_path
fd, self.tmp_file_path = tempfile.mkstemp(prefix=self.file_path, dir="")
fd, self.tmp_file_path = tempfile.mkstemp(prefix=str(self.file_path), dir="")
os.close(fd)
with contextlib.suppress(OSError): # It may be that the source does not exist.
os.replace(self.file_path, self.tmp_file_path)
Expand Down

0 comments on commit 1ddf953

Please sign in to comment.