]> arthur.barton.de Git - bup.git/blob - t/ns-timestamp-resolutions
07631276c1e441e58b28bb2e704ed87073a3d048
[bup.git] / t / ns-timestamp-resolutions
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7
8 import os, sys
9
10 argv = sys.argv
11 exe = os.path.realpath(argv[0])
12 exepath = os.path.split(exe)[0] or '.'
13 exeprefix = os.path.split(os.path.abspath(exepath))[0]
14
15 # fix the PYTHONPATH to include our lib dir
16 libpath = os.path.join(exepath, '..', 'lib')
17 sys.path[:0] = [libpath]
18 os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
19
20 import bup.xstat as xstat
21 from bup.helpers import handle_ctrl_c, saved_errors
22 from bup import metadata, options
23
24 optspec = """
25 ns-timestamp-resolutions TEST_FILE_NAME
26 --
27 """
28
29 handle_ctrl_c()
30
31 o = options.Options(optspec)
32 (opt, flags, extra) = o.parse(sys.argv[1:])
33
34 if len(extra) != 1:
35     o.fatal('must specify a test file name')
36
37 target = extra[0]
38
39 open(target, 'w').close()
40 xstat.utime(target, (123456789, 123456789))
41 meta = metadata.from_path(target)
42
43 def ns_resolution(x):
44     n = 1;
45     while n < 10**9 and x % 10 == 0:
46         x /= 10
47         n *= 10
48     return n
49
50 print ns_resolution(meta.atime), ns_resolution(meta.mtime)
51
52 if saved_errors:
53     log('warning: %d errors encountered\n' % len(saved_errors))
54     sys.exit(1)