]> arthur.barton.de Git - bup.git/blob - dev/ns-timestamp-resolutions
make: add check-py2 and check-py3 targets
[bup.git] / dev / ns-timestamp-resolutions
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_exec="$(dirname "$0")/bup-exec" || exit $?
4 exec "$bup_exec" "$0" ${1+"$@"}
5 """
6
7 from __future__ import absolute_import
8 import os.path, sys
9
10 from bup.compat import argv_bytes, get_argvb
11 from bup.helpers import handle_ctrl_c, saved_errors
12 from bup.io import byte_stream
13 from bup import compat, metadata, options
14 import bup.xstat as xstat
15
16
17 optspec = """
18 ns-timestamp-resolutions TEST_FILE_NAME
19 --
20 """
21
22 handle_ctrl_c()
23
24 o = options.Options(optspec)
25 opt, flags, extra = o.parse_bytes(get_argvb()[1:])
26
27 sys.stdout.flush()
28 out = byte_stream(sys.stdout)
29
30 if len(extra) != 1:
31     o.fatal('must specify a test file name')
32
33 target = argv_bytes(extra[0])
34
35 open(target, 'w').close()
36 xstat.utime(target, (123456789, 123456789))
37 meta = metadata.from_path(target)
38
39 def ns_resolution(x):
40     n = 1;
41     while n < 10**9 and x % 10 == 0:
42         x /= 10
43         n *= 10
44     return n
45
46 out.write(b'%d %d\n' % (ns_resolution(meta.atime),
47                         ns_resolution(meta.mtime)))
48
49 if saved_errors:
50     log('warning: %d errors encountered\n' % len(saved_errors))
51     sys.exit(1)