diff options
author | Christopher Bartz <bartz@dkrz.de> | 2017-07-06 17:30:48 +0200 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2017-07-06 10:19:12 -0700 |
commit | cde73c196d4f161b227fb924cd59cf02eaa33c03 (patch) | |
tree | 6e4314a1d68974f4f00ab90b7162ab83e33f9e6b /swiftclient | |
parent | 1d57403668815ab8cef9d6598c06bf1c7e5355c0 (diff) | |
download | python-swiftclient-cde73c196d4f161b227fb924cd59cf02eaa33c03.tar.gz |
Option to ignore mtime metadata entry.
Currently, the swiftclient upload command passes a custom metadata
header for each object (called object-meta-mtime), whose value is
the current UNIX timestamp. When downloading such an object with the
swiftclient, the mtime header is parsed and passed as the atime and
mtime for the newly created file.
There are use-cases where this is not desired, for example when using
tmp or scratch directories in which files older than a specific date
are deleted. This commit provides a boolean option for ignoring the
mtime header.
Change-Id: If60b389aa910c6f1969b999b5d3b6d0940375686
Diffstat (limited to 'swiftclient')
-rw-r--r-- | swiftclient/service.py | 4 | ||||
-rwxr-xr-x | swiftclient/shell.py | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/swiftclient/service.py b/swiftclient/service.py index b9b843e..5a43bf2 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -203,6 +203,7 @@ _default_local_options = { 'shuffle': False, 'destination': None, 'fresh_metadata': False, + 'ignore_mtime': False, } POLICY = 'X-Storage-Policy' @@ -1240,7 +1241,8 @@ class SwiftService(object): bytes_read = obj_body.bytes_read() if fp is not None: fp.close() - if 'x-object-meta-mtime' in headers and not no_file: + if ('x-object-meta-mtime' in headers and not no_file + and not options['ignore_mtime']): try: mtime = float(headers['x-object-meta-mtime']) except ValueError: diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 841ed6e..19a224a 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -272,6 +272,9 @@ Optional arguments: script to multiple servers). Enable this option to submit download jobs to the thread pool in the order they are listed in the object store. + --ignore-mtime Ignore the 'X-Object-Meta-Mtime' header when + downloading an object. Instead, create atime and mtime + with fresh timestamps. '''.strip("\n") @@ -332,6 +335,12 @@ def st_download(parser, args, output_manager): 'nightly automated download script to multiple servers). Enable this ' 'option to submit download jobs to the thread pool in the order they ' 'are listed in the object store.') + parser.add_argument( + '--ignore-mtime', action='store_true', dest='ignore_mtime', + default=False, help='By default, the object-meta-mtime header is used ' + 'to store the access and modified timestamp for the downloaded file. ' + 'With this option, the header is ignored and the timestamps are ' + 'created freshly.') (options, args) = parse_args(parser, args) args = args[1:] if options['out_file'] == '-': |