Skip to content

Commit 71a9887

Browse files
authored
fix: try to avoid creating temp dirs in the current working directory (#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).
1 parent a11ba7f commit 71a9887

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

plumbum/machines/remote.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ def pgrep(self, pattern):
325325
def tempdir(self):
326326
"""A context manager that creates a remote temporary directory, which is removed when
327327
the context exits"""
328-
_, out, _ = self._session.run("mktemp -d tmp.XXXXXXXXXX")
328+
_, out, _ = self._session.run(
329+
"mktemp -d 2>/dev/null || mktemp -d tmp.XXXXXXXXXX"
330+
)
329331
dir = self.path(out.strip()) # @ReservedAssignment
330332
try:
331333
yield dir

0 commit comments

Comments
 (0)