| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Archives a set of files or directories to an Isolate Server.""" | 6 """Archives a set of files or directories to an Isolate Server.""" |
| 7 | 7 |
| 8 __version__ = '0.6.0' | 8 __version__ = '0.6.0' |
| 9 | 9 |
| 10 import base64 | 10 import base64 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 import tempfile | 21 import tempfile |
| 22 import threading | 22 import threading |
| 23 import time | 23 import time |
| 24 import types | 24 import types |
| 25 import zlib | 25 import zlib |
| 26 | 26 |
| 27 from third_party import colorama | 27 from third_party import colorama |
| 28 from third_party.depot_tools import fix_encoding | 28 from third_party.depot_tools import fix_encoding |
| 29 from third_party.depot_tools import subcommand | 29 from third_party.depot_tools import subcommand |
| 30 | 30 |
| 31 from libs import arfile |
| 31 from utils import file_path | 32 from utils import file_path |
| 32 from utils import fs | 33 from utils import fs |
| 33 from utils import logging_utils | 34 from utils import logging_utils |
| 34 from utils import lru | 35 from utils import lru |
| 35 from utils import net | 36 from utils import net |
| 36 from utils import on_error | 37 from utils import on_error |
| 37 from utils import subprocess42 | 38 from utils import subprocess42 |
| 38 from utils import threading_utils | 39 from utils import threading_utils |
| 39 from utils import tools | 40 from utils import tools |
| 40 | 41 |
| (...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2064 | 2065 |
| 2065 # Wait for any item to finish fetching to cache. | 2066 # Wait for any item to finish fetching to cache. |
| 2066 digest = fetch_queue.wait(remaining) | 2067 digest = fetch_queue.wait(remaining) |
| 2067 | 2068 |
| 2068 # Create the files in the destination using item in cache as the | 2069 # Create the files in the destination using item in cache as the |
| 2069 # source. | 2070 # source. |
| 2070 for filepath, props in remaining.pop(digest): | 2071 for filepath, props in remaining.pop(digest): |
| 2071 fullpath = os.path.join(outdir, filepath) | 2072 fullpath = os.path.join(outdir, filepath) |
| 2072 | 2073 |
| 2073 with cache.getfileobj(digest) as srcfileobj: | 2074 with cache.getfileobj(digest) as srcfileobj: |
| 2074 file_mode = props.get('m') | 2075 filetype = props.get('t', 'basic') |
| 2075 if file_mode: | 2076 |
| 2076 # Ignore all bits apart from the user | 2077 if filetype == 'basic': |
| 2077 file_mode &= 0700 | 2078 file_mode = props.get('m') |
| 2078 putfile( | 2079 if file_mode: |
| 2079 srcfileobj, fullpath, file_mode, | 2080 # Ignore all bits apart from the user |
| 2080 use_symlink=use_symlinks) | 2081 file_mode &= 0700 |
| 2082 putfile( |
| 2083 srcfileobj, fullpath, file_mode, |
| 2084 use_symlink=use_symlinks) |
| 2085 |
| 2086 elif filetype == 'ar': |
| 2087 basedir = os.path.dirname(fullpath) |
| 2088 extractor = arfile.ArFileReader(srcfileobj, fullparse=False) |
| 2089 for ai, ifd in extractor: |
| 2090 fp = os.path.normpath(os.path.join(basedir, ai.name)) |
| 2091 file_path.ensure_tree(os.path.dirname(fp)) |
| 2092 putfile(ifd, fp, 0700, ai.size) |
| 2093 |
| 2094 else: |
| 2095 raise isolated_format.IsolatedError( |
| 2096 'Unknown file type %r', filetype) |
| 2081 | 2097 |
| 2082 # Report progress. | 2098 # Report progress. |
| 2083 duration = time.time() - last_update | 2099 duration = time.time() - last_update |
| 2084 if duration > DELAY_BETWEEN_UPDATES_IN_SECS: | 2100 if duration > DELAY_BETWEEN_UPDATES_IN_SECS: |
| 2085 msg = '%d files remaining...' % len(remaining) | 2101 msg = '%d files remaining...' % len(remaining) |
| 2086 print msg | 2102 print msg |
| 2087 logging.info(msg) | 2103 logging.info(msg) |
| 2088 last_update = time.time() | 2104 last_update = time.time() |
| 2089 | 2105 |
| 2090 # Cache could evict some items we just tried to fetch, it's a fatal error. | 2106 # Cache could evict some items we just tried to fetch, it's a fatal error. |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 return dispatcher.execute(OptionParserIsolateServer(), args) | 2431 return dispatcher.execute(OptionParserIsolateServer(), args) |
| 2416 | 2432 |
| 2417 | 2433 |
| 2418 if __name__ == '__main__': | 2434 if __name__ == '__main__': |
| 2419 subprocess42.inhibit_os_error_reporting() | 2435 subprocess42.inhibit_os_error_reporting() |
| 2420 fix_encoding.fix_encoding() | 2436 fix_encoding.fix_encoding() |
| 2421 tools.disable_buffering() | 2437 tools.disable_buffering() |
| 2422 colorama.init() | 2438 colorama.init() |
| 2423 file_path.enable_symlink() | 2439 file_path.enable_symlink() |
| 2424 sys.exit(main(sys.argv[1:])) | 2440 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |