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

Side by Side Diff: client/utils/file_path.py

Issue 1390773002: Add an assert to ensure UTF-8 locale when handling file paths. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: More fixes Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « client/tools/zip_profiler.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Swarming Authors. All rights reserved. 1 # Copyright 2013 The Swarming Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 that 2 # Use of this source code is governed under the Apache License, Version 2.0 that
3 # can be found in the LICENSE file. 3 # can be found in the LICENSE file.
4 4
5 """Provides functions: get_native_path_case(), isabs() and safe_join(). 5 """Provides functions: get_native_path_case(), isabs() and safe_join().
6 6
7 This module assumes that filesystem is not changing while current process 7 This module assumes that filesystem is not changing while current process
8 is running and thus it caches results of functions that depend on FS state. 8 is running and thus it caches results of functions that depend on FS state.
9 """ 9 """
10 10
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 866
867 On Windows, forcibly kills processes that are found to interfere with the 867 On Windows, forcibly kills processes that are found to interfere with the
868 deletion. 868 deletion.
869 869
870 Returns: 870 Returns:
871 True on normal execution, False if berserk techniques (like killing 871 True on normal execution, False if berserk techniques (like killing
872 processes) had to be used. 872 processes) had to be used.
873 """ 873 """
874 # Do not assert here yet because this would break too much code. 874 # Do not assert here yet because this would break too much code.
875 root = unicode(root) 875 root = unicode(root)
876 assert sys.getdefaultencoding() == 'utf-8', sys.getdefaultencoding()
876 make_tree_deleteable(root) 877 make_tree_deleteable(root)
877 logging.info('rmtree(%s)', root) 878 logging.info('rmtree(%s)', root)
878 879
879 # First try the soft way: tries 3 times to delete and sleep a bit in between. 880 # First try the soft way: tries 3 times to delete and sleep a bit in between.
880 # Retries help if test subprocesses outlive main process and try to actively 881 # Retries help if test subprocesses outlive main process and try to actively
881 # use or write to the directory while it is being deleted. 882 # use or write to the directory while it is being deleted.
882 max_tries = 3 883 max_tries = 3
883 for i in xrange(max_tries): 884 for i in xrange(max_tries):
884 # errors is a list of tuple(function, path, excinfo). 885 # errors is a list of tuple(function, path, excinfo).
885 errors = [] 886 errors = []
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 errors = [] 960 errors = []
960 shutil.rmtree(root, onerror=lambda *args: errors.append(args)) 961 shutil.rmtree(root, onerror=lambda *args: errors.append(args))
961 if errors: 962 if errors:
962 # There's no hope. 963 # There's no hope.
963 sys.stderr.write( 964 sys.stderr.write(
964 'Failed to delete %s. The following files remain:\n' % root) 965 'Failed to delete %s. The following files remain:\n' % root)
965 for _, path, _ in errors: 966 for _, path, _ in errors:
966 sys.stderr.write('- %s\n' % path) 967 sys.stderr.write('- %s\n' % path)
967 raise errors[0][2][0], errors[0][2][1], errors[0][2][2] 968 raise errors[0][2][0], errors[0][2][1], errors[0][2][2]
968 return False 969 return False
OLDNEW
« no previous file with comments | « client/tools/zip_profiler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698