Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: client/run_isolated.py

Issue 2663023004: swarming: delete named cache symlinks before workdir (Closed)
Patch Set: pylint Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/named_cache.py ('k') | client/tests/run_isolated_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/run_isolated.py
diff --git a/client/run_isolated.py b/client/run_isolated.py
index 2ab97bda51030cecc01c735a381f1e7f209f9aca..547a042b254f5467af7762fba7df54f35baf4f3b 100755
--- a/client/run_isolated.py
+++ b/client/run_isolated.py
@@ -490,16 +490,15 @@ def map_and_run(
command = process_command(command, out_dir, bot_file)
file_path.ensure_command_has_abs_path(command, cwd)
- init_named_caches(run_dir)
-
- sys.stdout.flush()
- start = time.time()
- try:
- result['exit_code'], result['had_hard_timeout'] = run_command(
- command, cwd, get_command_env(tmp_dir, cipd_info),
- hard_timeout, grace_period)
- finally:
- result['duration'] = max(time.time() - start, 0)
+ with init_named_caches(run_dir):
+ sys.stdout.flush()
+ start = time.time()
+ try:
+ result['exit_code'], result['had_hard_timeout'] = run_command(
+ command, cwd, get_command_env(tmp_dir, cipd_info),
+ hard_timeout, grace_period)
+ finally:
+ result['duration'] = max(time.time() - start, 0)
except Exception as e:
# An internal error occurred. Report accordingly so the swarming task will
# be retried automatically.
@@ -598,8 +597,8 @@ def run_tha_test(
isolate_cache: an isolateserver.LocalCache to keep from retrieving the
same objects constantly by caching the objects retrieved.
Can be on-disk or in-memory.
- init_named_caches: a function (run_dir) => void that creates symlinks for
- named caches in |run_dir|.
+ init_named_caches: a function (run_dir) => context manager that creates
+ symlinks for named caches in |run_dir|.
leak_temp_dir: if true, the temporary directory will be deliberately leaked
for later examination.
result_json: file path to dump result metadata into. If set, the process
@@ -961,9 +960,17 @@ def main(args):
options.cipd_server, options.cipd_client_package,
options.cipd_client_version, cache_dir=options.cipd_cache)
+ @contextlib.contextmanager
def init_named_caches(run_dir):
+ # WARNING: this function depends on "options" variable defined in the outer
+ # function.
with named_cache_manager.open():
named_cache_manager.create_symlinks(run_dir, options.named_caches)
+ try:
+ yield
+ finally:
+ if not options.leak_temp_dir:
+ named_cache_manager.delete_symlinks(run_dir, options.named_caches)
try:
command = [] if options.isolated else args
« no previous file with comments | « client/named_cache.py ('k') | client/tests/run_isolated_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698