Skip to content

Commit

Permalink
fix: try to avoid creating temp dirs in the current working directory (
Browse files Browse the repository at this point in the history
…#571)

Try to use `mktemp -d` before falling back to calling mktemp with an
explicit template (for compat. with some BSD variants of mktemp
(see #176)).

Testing shows shows that this fixes temp dirs being created in the
current working directory on systems using a recent current GNU
coreutils mktemp variant and on systems using the mktemp variant
packaged with some macOS versions (e.g. 10.15). This may also fix the
issue on other systems as well (see
https://stackoverflow.com/a/2792789).
  • Loading branch information
gschaffner authored Dec 23, 2021
1 parent a11ba7f commit 71a9887
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plumbum/machines/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def pgrep(self, pattern):
def tempdir(self):
"""A context manager that creates a remote temporary directory, which is removed when
the context exits"""
_, out, _ = self._session.run("mktemp -d tmp.XXXXXXXXXX")
_, out, _ = self._session.run(
"mktemp -d 2>/dev/null || mktemp -d tmp.XXXXXXXXXX"
)
dir = self.path(out.strip()) # @ReservedAssignment
try:
yield dir
Expand Down

0 comments on commit 71a9887

Please sign in to comment.