]> arthur.barton.de Git - bup.git/blob - t/ns-timestamp-resolutions
features: show version number of the Python interpreter
[bup.git] / t / ns-timestamp-resolutions
1 #!/bin/sh
2 """": # -*-python-*-
3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
5 arg_i=1
6 for arg in "$@"; do
7     export "BUP_ARGV_${arg_i}"="$arg"
8     shift
9     arg_i=$((arg_i + 1))
10 done
11 bup_python="$(dirname "$0")/../dev/bup-python" || exit $?
12 exec "$bup_python" "$0"
13 """
14 # end of bup preamble
15
16 from __future__ import absolute_import
17 import os.path, sys
18
19 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../lib']
20
21 from bup.compat import argv_bytes
22 from bup.helpers import handle_ctrl_c, saved_errors
23 from bup.io import byte_stream
24 from bup import compat, metadata, options
25 import bup.xstat as xstat
26
27
28 optspec = """
29 ns-timestamp-resolutions TEST_FILE_NAME
30 --
31 """
32
33 handle_ctrl_c()
34
35 o = options.Options(optspec)
36 opt, flags, extra = o.parse(compat.argv[1:])
37
38 sys.stdout.flush()
39 out = byte_stream(sys.stdout)
40
41 if len(extra) != 1:
42     o.fatal('must specify a test file name')
43
44 target = argv_bytes(extra[0])
45
46 open(target, 'w').close()
47 xstat.utime(target, (123456789, 123456789))
48 meta = metadata.from_path(target)
49
50 def ns_resolution(x):
51     n = 1;
52     while n < 10**9 and x % 10 == 0:
53         x /= 10
54         n *= 10
55     return n
56
57 out.write(b'%d %d\n' % (ns_resolution(meta.atime),
58                         ns_resolution(meta.mtime)))
59
60 if saved_errors:
61     log('warning: %d errors encountered\n' % len(saved_errors))
62     sys.exit(1)