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/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 04fde1b..a69cd0d 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -908,7 +908,7 @@
ldpaths = lddtree.LoadLdpaths(root)
targets = ExpandTargets(targets_wanted)
- with osutils.TempDirContextManager() as tempdir:
+ with osutils.TempDir() as tempdir:
# We have to split the root generation from the compression stages. This is
# because we hardlink in all the files (to avoid overhead of reading/writing
# the copies multiple times). But tar gets angry if a file's hardlink count