Make osutils.TempDir more generally useful.
- osutils.TempDirContextManager is renamed to osutils.TempDir.
- osutils.TempDir is now a class. It can be used both as a context manager and
as a regular object.
- osutils.TempDir now only sets itself as the global temporary directory if
requested. This helps prevent unexpected behavior (e.g. unrelated temporary
files are stored in this tempdir, and are deleted when context manager exits.)
BUG=chromium:212327
TEST=All unit tests. Trybot runs.
Change-Id: I0cb9b5d3174c380922c23661fb58c72b94e6e865
Reviewed-on: https://gerrit.chromium.org/gerrit/46520
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: David James <davidjames@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: David James <davidjames@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index b6d01a7..e7d24f8 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -551,7 +551,7 @@
return
# Create a hardlink in a tempdir and see if we get back EPERM.
- with osutils.TempDirContextManager() as tempdir:
+ with osutils.TempDir() as tempdir:
try:
os.link('/bin/sh', os.path.join(tempdir, 'sh'))
except OSError as e:
@@ -1268,7 +1268,7 @@
if not options.resume:
# If we're in resume mode, use our parents tempdir rather than
# nesting another layer.
- stack.Add(osutils.TempDirContextManager, prefix='cbuildbot-tmp')
+ stack.Add(osutils.TempDir, prefix='cbuildbot-tmp', set_global=True)
logging.debug("Cbuildbot tempdir is %r.", os.environ.get('TMP'))
# TODO(ferringb): update this once https://gerrit.chromium.org/gerrit/25359