#!/bin/sh
"""": # -*-python-*-
bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
exec "$bup_python" "$0" ${1+"$@"}
"""
# end of bup preamble

import os, sys

argv = sys.argv
exe = os.path.realpath(argv[0])
exepath = os.path.split(exe)[0] or '.'
exeprefix = os.path.split(os.path.abspath(exepath))[0]

# fix the PYTHONPATH to include our lib dir
libpath = os.path.join(exepath, '..', 'lib')
sys.path[:0] = [libpath]
os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')

import bup.xstat as xstat
from bup.helpers import handle_ctrl_c, saved_errors
from bup import metadata, options

optspec = """
ns-timestamp-resolutions TEST_FILE_NAME
--
"""

handle_ctrl_c()

o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])

if len(extra) != 1:
    o.fatal('must specify a test file name')

target = extra[0]

open(target, 'w').close()
xstat.utime(target, (123456789, 123456789))
meta = metadata.from_path(target)

def ns_resolution(x):
    n = 1;
    while n < 10**9 and x % 10 == 0:
        x /= 10
        n *= 10
    return n

print ns_resolution(meta.atime), ns_resolution(meta.mtime)

if saved_errors:
    log('warning: %d errors encountered\n' % len(saved_errors))
    sys.exit(1)
