| Index: third_party/WebKit/Tools/Scripts/merge-layout-test-results
|
| diff --git a/third_party/WebKit/Tools/Scripts/merge-layout-test-results b/third_party/WebKit/Tools/Scripts/merge-layout-test-results
|
| index 80a2d416930763cbdbb8cd7d8f6e312b872109c5..4cc323a37168ae6376a59d65cafad98471ebc54d 100755
|
| --- a/third_party/WebKit/Tools/Scripts/merge-layout-test-results
|
| +++ b/third_party/WebKit/Tools/Scripts/merge-layout-test-results
|
| @@ -8,45 +8,39 @@ import argparse
|
| import json
|
| import logging
|
| import os
|
| +import stat
|
| import shutil
|
| import sys
|
| import tempfile
|
| import time
|
|
|
| +from webkitpy.common.system.filesystem import FileSystem
|
| from webkitpy.common.system.log_utils import configure_logging
|
| from webkitpy.layout_tests import merge_results
|
|
|
| # ------------------------------------------------------------------------
|
| -
|
| -def rmtree(dirname):
|
| - # Attempt to remove a directory tree. We try multiple times as on Windows a
|
| - # process which is currently closing could still have a file open in the
|
| - # directory.
|
| - logging.info('Removing %s', dirname)
|
| - errors = []
|
| - def onerror(func, path, exc_info):
|
| - errors.append(path)
|
| - logging.exception('Failed at %s %s: %r', func, path, exc_info)
|
| -
|
| - attempts = 0
|
| - while attempts < 5:
|
| - del errors[:]
|
| - shutil.rmtree(dirname, onerror=onerror)
|
| - if not errors:
|
| - break
|
| - attempts += 1
|
| - time.sleep(1)
|
| -
|
| - # Check the path is gone.
|
| - if not os.path.exists(dirname):
|
| +def ensure_empty_dir(fs, directory, allow_existing, remove_existing):
|
| + """Ensure an empty directory exists.
|
| +
|
| + Args:
|
| + allow_existing (bool): Allow the empty directory to already exist.
|
| + remove_existing (bool): Remove the contents if the directory
|
| + already exists.
|
| + """
|
| + if not fs.exists(directory):
|
| + fs.maybe_make_directory(directory)
|
| return
|
|
|
| - logging.warning('Unable to remove %s', dirname)
|
| - for dirpath, dirnames, filenames in os.walk(dirname, onerror=onerror, topdown=False):
|
| - for fname in filenames:
|
| - logging.warning('File %s still in output dir.', os.path.join(dirpath, fname))
|
| - for dname in dirnames:
|
| - logging.warning('Dir %s still in output dir.', os.path.join(dirpath, dname))
|
| + logging.warning('Output directory exists %r', directory)
|
| + if not allow_existing:
|
| + raise IOError(
|
| + ('Output directory %s exists!\n'
|
| + 'Use --allow-existing-output-directory to continue') % directory)
|
| +
|
| + if remove_existing and not fs.remove_contents(directory):
|
| + raise IOError(
|
| + ('Unable to remove output directory %s contents!\n'
|
| + 'See log output for errors.') % directory)
|
|
|
|
|
| def main(argv):
|
| @@ -156,9 +150,10 @@ directory. The script will be given the arguments plus
|
| for result_key, build_prop_key in args.results_json_override_with_build_property:
|
| results_json_value_overrides[result_key] = build_properties[build_prop_key]
|
|
|
| - assert not args.output_directory
|
| - args.output_directory = os.getcwd()
|
| - args.remove_existing_output_directory = True
|
| + if not args.output_directory:
|
| + args.output_directory = os.getcwd()
|
| + args.allow_existing_output_directory = True
|
| + args.remove_existing_output_directory = True
|
|
|
| assert not args.input_directories
|
| args.input_directories = [os.path.dirname(f) for f in args.positional]
|
| @@ -186,14 +181,12 @@ directory. The script will be given the arguments plus
|
| merger = merge_results.LayoutTestDirMerger(
|
| results_json_value_overrides=results_json_value_overrides,
|
| results_json_allow_unknown_if_matching=args.results_json_allow_unknown_if_matching)
|
| - if os.path.exists(args.output_directory):
|
| - logging.warning('Output directory exists %r', args.output_directory)
|
| - if args.remove_existing_output_directory:
|
| - rmtree(args.output_directory)
|
| - elif not args.allow_existing_output_directory:
|
| - raise IOError(
|
| - ('Output directory %s exists!\n'
|
| - 'Use --allow-existing-output-directory to continue') % args.output_directory)
|
| +
|
| + ensure_empty_dir(
|
| + FileSystem(),
|
| + args.output_directory,
|
| + allow_existing=args.allow_existing_output_directory,
|
| + remove_existing=args.remove_existing_output_directory)
|
|
|
| merger.merge(args.output_directory, args.input_directories)
|
|
|
|
|