| OLD | NEW |
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that 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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 | 719 |
| 720 | 720 |
| 721 def set_read_only_swallow(path, read_only): | 721 def set_read_only_swallow(path, read_only): |
| 722 """Returns if an OSError exception occured.""" | 722 """Returns if an OSError exception occured.""" |
| 723 try: | 723 try: |
| 724 set_read_only(path, read_only) | 724 set_read_only(path, read_only) |
| 725 except OSError as e: | 725 except OSError as e: |
| 726 return e | 726 return e |
| 727 | 727 |
| 728 | 728 |
| 729 def remove(filepath): |
| 730 """Removes a file, even if it is read-only.""" |
| 731 # TODO(maruel): Not do it unless necessary since it slows this function |
| 732 # down. |
| 733 if sys.platform == 'win32': |
| 734 # Deleting a read-only file will fail if it is read-only. |
| 735 set_read_only(filepath, False) |
| 736 else: |
| 737 # Deleting a read-only file will fail if the directory is read-only. |
| 738 set_read_only(os.path.dirname(filepath), False) |
| 739 fs.remove(filepath) |
| 740 |
| 741 |
| 729 def try_remove(filepath): | 742 def try_remove(filepath): |
| 730 """Removes a file without crashing even if it doesn't exist.""" | 743 """Removes a file without crashing even if it doesn't exist.""" |
| 731 try: | 744 try: |
| 732 # TODO(maruel): Not do it unless necessary since it slows this function | 745 remove(filepath) |
| 733 # down. | |
| 734 if sys.platform == 'win32': | |
| 735 # Deleting a read-only file will fail if it is read-only. | |
| 736 set_read_only(filepath, False) | |
| 737 else: | |
| 738 # Deleting a read-only file will fail if the directory is read-only. | |
| 739 set_read_only(os.path.dirname(filepath), False) | |
| 740 fs.remove(filepath) | |
| 741 except OSError: | 746 except OSError: |
| 742 pass | 747 pass |
| 743 | 748 |
| 744 | 749 |
| 745 def link_file(outfile, infile, action): | 750 def link_file(outfile, infile, action): |
| 746 """Links a file. The type of link depends on |action|. | 751 """Links a file. The type of link depends on |action|. |
| 747 | 752 |
| 748 Returns: | 753 Returns: |
| 749 True if the action was carried on, False if fallback was used. | 754 True if the action was carried on, False if fallback was used. |
| 750 """ | 755 """ |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 errors = [] | 1032 errors = [] |
| 1028 fs.rmtree(root, onerror=lambda *args: errors.append(args)) | 1033 fs.rmtree(root, onerror=lambda *args: errors.append(args)) |
| 1029 if errors: | 1034 if errors: |
| 1030 # There's no hope. | 1035 # There's no hope. |
| 1031 sys.stderr.write( | 1036 sys.stderr.write( |
| 1032 'Failed to delete %s. The following files remain:\n' % root) | 1037 'Failed to delete %s. The following files remain:\n' % root) |
| 1033 for _, path, _ in errors: | 1038 for _, path, _ in errors: |
| 1034 sys.stderr.write('- %s\n' % path) | 1039 sys.stderr.write('- %s\n' % path) |
| 1035 raise errors[0][2][0], errors[0][2][1], errors[0][2][2] | 1040 raise errors[0][2][0], errors[0][2][1], errors[0][2][2] |
| 1036 return False | 1041 return False |
| OLD | NEW |