3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/bup-python" || exit $?
13 exec "$bup_python" "$0"
17 # Copyright (C) 2010 Rob Browning
19 # This code is covered under the terms of the GNU Library General
20 # Public License as described in the bup LICENSE file.
22 from __future__ import absolute_import, print_function
23 import sys, stat, errno
25 from bup import compat, metadata, options, xstat
26 from bup.compat import argv_bytes
27 from bup.helpers import add_error, handle_ctrl_c, parse_timestamp, saved_errors, \
29 from bup.io import byte_stream
32 def parse_timestamp_arg(field, value):
33 res = str(value) # Undo autoconversion.
35 res = parse_timestamp(res)
36 except ValueError as ex:
38 o.fatal('unable to parse %s resolution "%s" (%s)'
41 o.fatal('unable to parse %s resolution "%s"' % (field, value))
43 if res != 1 and res % 10:
44 o.fatal('%s resolution "%s" must be a power of 10' % (field, value))
49 bup xstat pathinfo [OPTION ...] <PATH ...>
51 v,verbose increase log output (can be used more than once)
52 q,quiet don't show progress meter
53 exclude-fields= exclude comma-separated fields
54 include-fields= include comma-separated fields (definitive if first)
55 atime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
56 mtime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
57 ctime-resolution= limit s, ms, us, ns, 10ns (value must be a power of 10) [ns]
61 active_fields = metadata.all_fields
65 o = options.Options(optspec)
66 (opt, flags, remainder) = o.parse(compat.argv[1:])
68 atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution)
69 mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution)
70 ctime_resolution = parse_timestamp_arg('ctime', opt.ctime_resolution)
72 treat_include_fields_as_definitive = True
73 for flag, value in flags:
74 if flag == '--exclude-fields':
75 exclude_fields = frozenset(value.split(','))
76 for f in exclude_fields:
77 if not f in metadata.all_fields:
78 o.fatal(f + ' is not a valid field name')
79 active_fields = active_fields - exclude_fields
80 treat_include_fields_as_definitive = False
81 elif flag == '--include-fields':
82 include_fields = frozenset(value.split(','))
83 for f in include_fields:
84 if not f in metadata.all_fields:
85 o.fatal(f + ' is not a valid field name')
86 if treat_include_fields_as_definitive:
87 active_fields = include_fields
88 treat_include_fields_as_definitive = False
90 active_fields = active_fields | include_fields
92 opt.verbose = opt.verbose or 0
93 opt.quiet = opt.quiet or 0
94 metadata.verbose = opt.verbose - opt.quiet
97 out = byte_stream(sys.stdout)
100 for path in remainder:
101 path = argv_bytes(path)
103 m = metadata.from_path(path, archive_path = path)
104 except (OSError,IOError) as e:
105 if e.errno == errno.ENOENT:
110 if metadata.verbose >= 0:
113 if atime_resolution != 1:
114 m.atime = (m.atime / atime_resolution) * atime_resolution
115 if mtime_resolution != 1:
116 m.mtime = (m.mtime / mtime_resolution) * mtime_resolution
117 if ctime_resolution != 1:
118 m.ctime = (m.ctime / ctime_resolution) * ctime_resolution
119 out.write(metadata.detailed_bytes(m, active_fields))
124 log('WARNING: %d errors encountered.\n' % len(saved_errors))