|
1 |
| -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 1 | +# Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | #
|
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You
|
4 | 4 | # may not use this file except in compliance with the License. A copy of
|
|
14 | 14 | from __future__ import absolute_import
|
15 | 15 |
|
16 | 16 | import os
|
| 17 | +import logging |
17 | 18 | import shutil
|
| 19 | +import errno |
18 | 20 |
|
19 | 21 | from distutils.dir_util import copy_tree
|
20 | 22 | from six.moves.urllib.parse import urlparse
|
21 | 23 |
|
22 | 24 | from sagemaker import s3
|
23 | 25 |
|
| 26 | +logger = logging.getLogger(__name__) |
| 27 | + |
24 | 28 |
|
25 | 29 | def copy_directory_structure(destination_directory, relative_path):
|
26 | 30 | """Creates intermediate directory structure for relative_path.
|
@@ -73,7 +77,19 @@ def move_to_destination(source, destination, job_name, sagemaker_session):
|
73 | 77 | else:
|
74 | 78 | raise ValueError("Invalid destination URI, must be s3:// or file://, got: %s" % destination)
|
75 | 79 |
|
76 |
| - shutil.rmtree(source) |
| 80 | + try: |
| 81 | + shutil.rmtree(source) |
| 82 | + except OSError as exc: |
| 83 | + # on Linux, when docker writes to any mounted volume, it uses the container's user. In most |
| 84 | + # cases this is root. When the container exits and we try to delete them we can't because |
| 85 | + # root owns those files. We expect this to happen, so we handle EACCESS. Any other error |
| 86 | + # we will raise the exception up. |
| 87 | + if exc.errno == errno.EACCES: |
| 88 | + logger.warning("Failed to delete: %s Please remove it manually.", source) |
| 89 | + else: |
| 90 | + logger.error("Failed to delete: %s", source) |
| 91 | + raise |
| 92 | + |
77 | 93 | return final_uri
|
78 | 94 |
|
79 | 95 |
|
|
0 commit comments