Пример #1
0
def test_timespec_behavior():
    if not _have_bup_utime_ns:
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        open(path, 'w').close()
        frac_ts = (0, 10**9 / 2)
        _helpers.bup_utime_ns(path, (frac_ts, frac_ts))
        st = _helpers.stat(path)
        atime_ts = st[8]
        mtime_ts = st[9]
        WVPASSEQ(atime_ts[0], 0)
        WVPASS(atime_ts[1] == 0 or atime_ts[1] == frac_ts[1])
        WVPASSEQ(mtime_ts[0], 0)
        WVPASS(mtime_ts[1] == 0 or mtime_ts[1] == frac_ts[1])
        if(mtime_ts[1] == frac_ts[1]):
            # Sub-second resolution -- check behavior of negative timespecs.
            neg_ts = (-43, 10**9 / 2)
            _helpers.bup_utime_ns(path, (neg_ts, neg_ts))
            st = _helpers.stat(path)
            atime_ts = st[8]
            mtime_ts = st[9]
            WVPASSEQ(atime_ts, neg_ts)
            WVPASSEQ(mtime_ts, neg_ts)
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
Пример #2
0
 def utime(path, times):
     """Times must be provided as (atime_ns, mtime_ns)."""
     atime = nsecs_to_timespec(times[0])
     mtime = nsecs_to_timespec(times[1])
     _helpers.bup_utime_ns(path, (atime, mtime))