Пример #1
0
    def getattr(self, path):
        log('--getattr(%r)\n' % path)
        try:
            node = cache_get(self.top, path)
            st = Stat()
            st.st_nlink = node.nlinks()
            st.st_size = node.size()  # Until/unless we store the size in m.
            if self.meta:
                m = node.metadata()
                if m:
                    st.st_mode = m.mode
                    st.st_uid = m.uid
                    st.st_gid = m.gid
                    st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
                    st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
                    st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
		    st.st_rdev = m.rdev
		else:
		    if self.mode:
		        mask = stat.S_ISDIR(node.mode) and 0111
			setmode = stat.S_ISLNK(node.mode) and 0777
		        st.st_mode = (self.mode & (0666 | mask)) | \
			             (node.mode & ~0777) | \
			             setmode
		    else:
			st.st_mode = node.mode
		    st.st_atime = node.atime
		    st.st_mtime = node.mtime
		    st.st_ctime = node.ctime
		    st.st_uid = self.uid or 0
		    st.st_gid = self.gid or 0
            return st
        except vfs.NoSuchFile:
            return -errno.ENOENT
Пример #2
0
 def getattr(self, path):
     path = argv_bytes(path)
     if self.verbose > 0:
         log('--getattr(%r)\n' % path)
     res = vfs.resolve(self.repo,
                       path,
                       want_meta=(not self.fake_metadata),
                       follow=False)
     name, item = res[-1]
     if not item:
         return -errno.ENOENT
     if self.fake_metadata:
         item = vfs.augment_item_meta(self.repo, item, include_size=True)
     else:
         item = vfs.ensure_item_has_metadata(self.repo,
                                             item,
                                             include_size=True)
     meta = item.meta
     # FIXME: do we want/need to do anything more with nlink?
     st = fuse.Stat(st_mode=meta.mode, st_nlink=1, st_size=meta.size)
     st.st_mode = meta.mode
     st.st_uid = meta.uid or 0
     st.st_gid = meta.gid or 0
     st.st_atime = max(0, xstat.fstime_floor_secs(meta.atime))
     st.st_mtime = max(0, xstat.fstime_floor_secs(meta.mtime))
     st.st_ctime = max(0, xstat.fstime_floor_secs(meta.ctime))
     return st
Пример #3
0
 def add(self, name, st, hashgen = None):
     endswith = name.endswith('/')
     ename = pathsplit(name)
     basename = ename[-1]
     #log('add: %r %r\n' % (basename, name))
     flags = IX_EXISTS
     sha = None
     if hashgen:
         (gitmode, sha) = hashgen(name)
         flags |= IX_HASHVALID
     else:
         (gitmode, sha) = (0, EMPTY_SHA)
     if st:
         isdir = stat.S_ISDIR(st.st_mode)
         assert(isdir == endswith)
         e = NewEntry(basename, name, self.tmax,
                      st.st_dev, st.st_ino, st.st_nlink,
                      xstat.fstime_floor_secs(st.st_ctime),
                      xstat.fstime_floor_secs(st.st_mtime),
                      st.st_uid, st.st_gid,
                      st.st_size, st.st_mode, gitmode, sha, flags,
                      0, 0)
     else:
         assert(endswith)
         e = BlankNewEntry(basename, tmax)
         e.gitmode = gitmode
         e.sha = sha
         e.flags = flags
     self._add(ename, e)
Пример #4
0
 def add(self, name, st, hashgen=None):
     endswith = name.endswith('/')
     ename = pathsplit(name)
     basename = ename[-1]
     #log('add: %r %r\n' % (basename, name))
     flags = IX_EXISTS
     sha = None
     if hashgen:
         (gitmode, sha) = hashgen(name)
         flags |= IX_HASHVALID
     else:
         (gitmode, sha) = (0, EMPTY_SHA)
     if st:
         isdir = stat.S_ISDIR(st.st_mode)
         assert (isdir == endswith)
         e = NewEntry(basename, name, self.tmax, st.st_dev, st.st_ino,
                      st.st_nlink, xstat.fstime_floor_secs(st.st_ctime),
                      xstat.fstime_floor_secs(st.st_mtime), st.st_uid,
                      st.st_gid, st.st_size, st.st_mode, gitmode, sha,
                      flags, 0, 0)
     else:
         assert (endswith)
         e = BlankNewEntry(basename, tmax)
         e.gitmode = gitmode
         e.sha = sha
         e.flags = flags
     self._add(ename, e)
Пример #5
0
 def __repr__(self):
     result = ['<%s instance at %s' % (self.__class__, hex(id(self)))]
     if self.path is not None:
         result += ' path:' + repr(self.path)
     if self.mode is not None:
         result += ' mode: %o (%s)' % (self.mode, xstat.mode_str(self.mode))
     if self.uid is not None:
         result += ' uid:' + str(self.uid)
     if self.gid is not None:
         result += ' gid:' + str(self.gid)
     if self.user is not None:
         result += ' user:'******' group:' + repr(self.group)
     if self.size is not None:
         result += ' size:' + repr(self.size)
     for name, val in (('atime', self.atime),
                       ('mtime', self.mtime),
                       ('ctime', self.ctime)):
         if val is not None:
             result += ' %s:%r (%d)' \
                       % (name,
                          strftime('%Y-%m-%d %H:%M %z',
                                   gmtime(xstat.fstime_floor_secs(val))),
                          val)
     result += '>'
     return ''.join(result)
Пример #6
0
 def from_stat(self, st, meta_ofs, tstart, check_device=True):
     old = (self.dev if check_device else 0,
            self.ino, self.nlink, self.ctime, self.mtime,
            self.uid, self.gid, self.size, self.flags & IX_EXISTS)
     new = (st.st_dev if check_device else 0,
            st.st_ino, st.st_nlink, st.st_ctime, st.st_mtime,
            st.st_uid, st.st_gid, st.st_size, IX_EXISTS)
     self.dev = st.st_dev
     self.ino = st.st_ino
     self.nlink = st.st_nlink
     self.ctime = st.st_ctime
     self.mtime = st.st_mtime
     self.atime = st.st_atime
     self.uid = st.st_uid
     self.gid = st.st_gid
     self.size = st.st_size
     self.mode = st.st_mode
     self.flags |= IX_EXISTS
     self.meta_ofs = meta_ofs
     # Check that the ctime's "second" is at or after tstart's.
     ctime_sec_in_ns = xstat.fstime_floor_secs(st.st_ctime) * 10**9
     if ctime_sec_in_ns >= tstart or old != new \
           or self.sha == EMPTY_SHA or not self.gitmode:
         self.invalidate()
     self._fixup()
Пример #7
0
 def __repr__(self):
     result = ['<%s instance at %s' % (self.__class__, hex(id(self)))]
     if self.path:
         result += ' path:' + repr(self.path)
     if self.mode:
         result += ' mode:' + repr(xstat.mode_str(self.mode)
                                   + '(%s)' % hex(self.mode))
     if self.uid:
         result += ' uid:' + str(self.uid)
     if self.gid:
         result += ' gid:' + str(self.gid)
     if self.user:
         result += ' user:'******' group:' + repr(self.group)
     if self.size:
         result += ' size:' + repr(self.size)
     for name, val in (('atime', self.atime),
                       ('mtime', self.mtime),
                       ('ctime', self.ctime)):
         result += ' %s:%r' \
             % (name,
                time.strftime('%Y-%m-%d %H:%M %z',
                              time.gmtime(xstat.fstime_floor_secs(val))))
     result += '>'
     return ''.join(result)
Пример #8
0
def test_fstime():
    WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
    WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
    WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
    WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
    WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
    WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
    WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
    WVEXCEPT(Exception, xstat.timespec_to_nsecs, (0, -1))
    WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
    WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))

    WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
    WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
    WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
    WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
    WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
    WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
    WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
    x = xstat.nsecs_to_timespec(1977777778)
    WVPASSEQ(type(x[0]), type(0))
    WVPASSEQ(type(x[1]), type(0))
    x = xstat.nsecs_to_timespec(-1977777778)
    WVPASSEQ(type(x[0]), type(0))
    WVPASSEQ(type(x[1]), type(0))

    WVPASSEQ(xstat.fstime_floor_secs(0), 0)
    WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
    WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
    WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
    WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
    WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
    WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
Пример #9
0
def test_fstime():
    WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
    WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
    WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
    WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
    WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
    WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
    WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
    WVEXCEPT(Exception, xstat.timespec_to_nsecs, (0, -1))
    WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
    WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))

    WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
    WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
    WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
    WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
    WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
    WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
    WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
    x = xstat.nsecs_to_timespec(1977777778)
    WVPASSEQ(type(x[0]), type(0))
    WVPASSEQ(type(x[1]), type(0))
    x = xstat.nsecs_to_timespec(-1977777778)
    WVPASSEQ(type(x[0]), type(0))
    WVPASSEQ(type(x[1]), type(0))

    WVPASSEQ(xstat.fstime_floor_secs(0), 0)
    WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
    WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
    WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
    WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
    WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
    WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
Пример #10
0
 def getattr(self, path):
     try:
         node = self.top.resolve(path)
         st = Stat()
         st.st_mode = node.mode
         st.st_nlink = node.nlinks()
         st.st_size = node.size()  # Until/unless we store the size in m.
         if self.meta:
             m = node.metadata()
             if m:
                 st.st_mode = m.mode
                 st.st_uid = m.uid
                 st.st_gid = m.gid
                 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
                 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
                 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
         return st
     except vfs.NoSuchFile:
         return -errno.ENOENT
Пример #11
0
 def getattr(self, path):
     try:
         node = self.top.resolve(path)
         st = Stat()
         st.st_mode = node.mode
         st.st_nlink = node.nlinks()
         st.st_size = node.size()  # Until/unless we store the size in m.
         if self.meta:
             m = node.metadata()
             if m:
                 st.st_mode = m.mode
                 st.st_uid = m.uid
                 st.st_gid = m.gid
                 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
                 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
                 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
         return st
     except vfs.NoSuchFile:
         return -errno.ENOENT
Пример #12
0
def summary_bytes(meta,
                  numeric_ids=False,
                  classification=None,
                  human_readable=False):
    """Return bytes containing the "ls -l" style listing for meta.
    Classification may be "all", "type", or None."""
    user_str = group_str = size_or_dev_str = b'?'
    symlink_target = None
    if meta:
        name = meta.path
        mode_str = xstat.mode_str(meta.mode).encode('ascii')
        symlink_target = meta.symlink_target
        mtime_secs = xstat.fstime_floor_secs(meta.mtime)
        mtime_str = strftime('%Y-%m-%d %H:%M',
                             time.localtime(mtime_secs)).encode('ascii')
        if meta.user and not numeric_ids:
            user_str = meta.user
        elif meta.uid != None:
            user_str = str(meta.uid).encode()
        if meta.group and not numeric_ids:
            group_str = meta.group
        elif meta.gid != None:
            group_str = str(meta.gid).encode()
        if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
            if meta.rdev:
                size_or_dev_str = (
                    '%d,%d' %
                    (os.major(meta.rdev), os.minor(meta.rdev))).encode()
        elif meta.size != None:
            if human_readable:
                size_or_dev_str = format_filesize(meta.size).encode()
            else:
                size_or_dev_str = str(meta.size).encode()
        else:
            size_or_dev_str = b'-'
        if classification:
            classification_str = \
                xstat.classification_str(meta.mode,
                                         classification == 'all').encode()
    else:
        mode_str = b'?' * 10
        mtime_str = b'????-??-?? ??:??'
        classification_str = b'?'

    name = name or b''
    if classification:
        name += classification_str
    if symlink_target:
        name += b' -> ' + meta.symlink_target

    return b'%-10s %-11s %11s %16s %s' % (mode_str,
                                          user_str + b'/' + group_str,
                                          size_or_dev_str, mtime_str, name)
Пример #13
0
 def getattr(self, path):
     log('--getattr(%r)\n' % path)
     try:
         node = self._cache_get(path)
         st = Stat()
         st.st_mode = node.mode
         st.st_nlink = node.nlinks()
         st.st_size = node.size()  # Until/unless we store the size in m.
         real_node = path.count('/') > 3
         if real_node:
             m = self.meta if self.meta else node.metadata()
             if m:
                 st.st_mode = m.mode
                 st.st_uid = opt.uid if opt.uid is not None else m.uid
                 st.st_gid = opt.gid if opt.gid is not None else m.gid
                 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
                 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
                 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
         return st
     except vfs.NoSuchFile:
         return -errno.ENOENT
Пример #14
0
 def getattr(self, path):
     if self.verbose > 0:
         log('--getattr(%r)\n' % path)
     try:
         node = cache_get(self.top, path)
         st = fuse.Stat(st_mode=node.mode,
                        st_nlink=node.nlinks(),
                        # Until/unless we store the size in m.
                        st_size=node.size())
         if self.meta:
             m = node.metadata()
             if m:
                 st.st_mode = m.mode
                 st.st_uid = m.uid
                 st.st_gid = m.gid
                 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
                 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
                 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
         return st
     except vfs.NoSuchFile:
         return -errno.ENOENT
Пример #15
0
 def from_stat(self, st, tstart):
     old = (self.dev, self.ino, self.nlink, self.ctime, self.mtime,
            self.uid, self.gid, self.size, self.flags & IX_EXISTS)
     new = (st.st_dev, st.st_ino, st.st_nlink,
            xstat.fstime_floor_secs(st.st_ctime),
            xstat.fstime_floor_secs(st.st_mtime), st.st_uid, st.st_gid,
            st.st_size, IX_EXISTS)
     self.dev = st.st_dev
     self.ino = st.st_ino
     self.nlink = st.st_nlink
     self.ctime = xstat.fstime_floor_secs(st.st_ctime)
     self.mtime = xstat.fstime_floor_secs(st.st_mtime)
     self.uid = st.st_uid
     self.gid = st.st_gid
     self.size = st.st_size
     self.mode = st.st_mode
     self.flags |= IX_EXISTS
     if xstat.fstime_floor_secs(st.st_ctime) >= tstart or old != new \
           or self.sha == EMPTY_SHA or not self.gitmode:
         self.invalidate()
     self._fixup()
Пример #16
0
 def from_stat(self, st, tstart):
     old = (self.dev, self.ino, self.nlink, self.ctime, self.mtime,
            self.uid, self.gid, self.size, self.flags & IX_EXISTS)
     new = (st.st_dev, st.st_ino, st.st_nlink,
            xstat.fstime_floor_secs(st.st_ctime),
            xstat.fstime_floor_secs(st.st_mtime),
            st.st_uid, st.st_gid, st.st_size, IX_EXISTS)
     self.dev = st.st_dev
     self.ino = st.st_ino
     self.nlink = st.st_nlink
     self.ctime = xstat.fstime_floor_secs(st.st_ctime)
     self.mtime = xstat.fstime_floor_secs(st.st_mtime)
     self.uid = st.st_uid
     self.gid = st.st_gid
     self.size = st.st_size
     self.mode = st.st_mode
     self.flags |= IX_EXISTS
     if xstat.fstime_floor_secs(st.st_ctime) >= tstart or old != new \
           or self.sha == EMPTY_SHA or not self.gitmode:
         self.invalidate()
     self._fixup()
Пример #17
0
 def getattr(self, path):
     if self.verbose > 0:
         log('--getattr(%r)\n' % path)
     try:
         node = cache_get(self.top, path)
         st = fuse.Stat(
             st_mode=node.mode,
             st_nlink=node.nlinks(),
             # Until/unless we store the size in m.
             st_size=node.size())
         if self.meta:
             m = node.metadata()
             if m:
                 st.st_mode = m.mode
                 st.st_uid = m.uid
                 st.st_gid = m.gid
                 st.st_atime = max(0, xstat.fstime_floor_secs(m.atime))
                 st.st_mtime = max(0, xstat.fstime_floor_secs(m.mtime))
                 st.st_ctime = max(0, xstat.fstime_floor_secs(m.ctime))
         return st
     except vfs.NoSuchFile:
         return -errno.ENOENT
Пример #18
0
def summary_str(meta, numeric_ids = False, classification = None,
                human_readable = False):

    """Return a string containing the "ls -l" style listing for meta.
    Classification may be "all", "type", or None."""
    user_str = group_str = size_or_dev_str = '?'
    symlink_target = None
    if meta:
        name = meta.path
        mode_str = xstat.mode_str(meta.mode)
        symlink_target = meta.symlink_target
        mtime_secs = xstat.fstime_floor_secs(meta.mtime)
        mtime_str = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
        if meta.user and not numeric_ids:
            user_str = meta.user
        elif meta.uid != None:
            user_str = str(meta.uid)
        if meta.group and not numeric_ids:
            group_str = meta.group
        elif meta.gid != None:
            group_str = str(meta.gid)
        if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
            if meta.rdev:
                size_or_dev_str = '%d,%d' % (os.major(meta.rdev),
                                             os.minor(meta.rdev))
        elif meta.size != None:
            if human_readable:
                size_or_dev_str = format_filesize(meta.size)
            else:
                size_or_dev_str = str(meta.size)
        else:
            size_or_dev_str = '-'
        if classification:
            classification_str = \
                xstat.classification_str(meta.mode, classification == 'all')
    else:
        mode_str = '?' * 10
        mtime_str = '????-??-?? ??:??'
        classification_str = '?'

    name = name or ''
    if classification:
        name += classification_str
    if symlink_target:
        name += ' -> ' + meta.symlink_target

    return '%-10s %-11s %11s %16s %s' % (mode_str,
                                         user_str + "/" + group_str,
                                         size_or_dev_str,
                                         mtime_str,
                                         name)
Пример #19
0
 def getattr(self, path):
     global opt
     if self.verbose > 0:
         log('--getattr(%r)\n' % path)
     res = vfs.resolve(self.repo, path, want_meta=(not self.fake_metadata),
                       follow=False)
     name, item = res[-1]
     if not item:
         return -errno.ENOENT
     if self.fake_metadata:
         item = vfs.augment_item_meta(self.repo, item, include_size=True)
     else:
         item = vfs.ensure_item_has_metadata(self.repo, item,
                                             include_size=True)
     meta = item.meta
     # FIXME: do we want/need to do anything more with nlink?
     st = fuse.Stat(st_mode=meta.mode, st_nlink=1, st_size=meta.size)
     st.st_mode = meta.mode
     st.st_uid = meta.uid
     st.st_gid = meta.gid
     st.st_atime = max(0, xstat.fstime_floor_secs(meta.atime))
     st.st_mtime = max(0, xstat.fstime_floor_secs(meta.mtime))
     st.st_ctime = max(0, xstat.fstime_floor_secs(meta.ctime))
     return st
Пример #20
0
def test_fstime():
    with no_lingering_errors():
        WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
        WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
        WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
        WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
        WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
        WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))

        WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
        WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
        WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
        WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
        WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
        WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
        WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
        x = xstat.nsecs_to_timespec(1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))
        x = xstat.nsecs_to_timespec(-1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))

        WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
        WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
        WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
        WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
        WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
        WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
        WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
        x = xstat.nsecs_to_timeval(1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))
        x = xstat.nsecs_to_timeval(-1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))

        WVPASSEQ(xstat.fstime_floor_secs(0), 0)
        WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
        WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
        WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
        WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
        WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
        WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
Пример #21
0
Файл: txstat.py Проект: bup/bup
def test_fstime():
    with no_lingering_errors():
        WVPASSEQ(xstat.timespec_to_nsecs((0, 0)), 0)
        WVPASSEQ(xstat.timespec_to_nsecs((1, 0)), 10**9)
        WVPASSEQ(xstat.timespec_to_nsecs((0, 10**9 / 2)), 500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((1, 10**9 / 2)), 1500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((-1, 0)), -10**9)
        WVPASSEQ(xstat.timespec_to_nsecs((-1, 10**9 / 2)), -500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((-2, 10**9 / 2)), -1500000000)
        WVPASSEQ(xstat.timespec_to_nsecs((0, -1)), -1)
        WVPASSEQ(type(xstat.timespec_to_nsecs((2, 22222222))), type(0))
        WVPASSEQ(type(xstat.timespec_to_nsecs((-2, 22222222))), type(0))

        WVPASSEQ(xstat.nsecs_to_timespec(0), (0, 0))
        WVPASSEQ(xstat.nsecs_to_timespec(10**9), (1, 0))
        WVPASSEQ(xstat.nsecs_to_timespec(500000000), (0, 10**9 / 2))
        WVPASSEQ(xstat.nsecs_to_timespec(1500000000), (1, 10**9 / 2))
        WVPASSEQ(xstat.nsecs_to_timespec(-10**9), (-1, 0))
        WVPASSEQ(xstat.nsecs_to_timespec(-500000000), (-1, 10**9 / 2))
        WVPASSEQ(xstat.nsecs_to_timespec(-1500000000), (-2, 10**9 / 2))
        x = xstat.nsecs_to_timespec(1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))
        x = xstat.nsecs_to_timespec(-1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))

        WVPASSEQ(xstat.nsecs_to_timeval(0), (0, 0))
        WVPASSEQ(xstat.nsecs_to_timeval(10**9), (1, 0))
        WVPASSEQ(xstat.nsecs_to_timeval(500000000), (0, (10**9 / 2) / 1000))
        WVPASSEQ(xstat.nsecs_to_timeval(1500000000), (1, (10**9 / 2) / 1000))
        WVPASSEQ(xstat.nsecs_to_timeval(-10**9), (-1, 0))
        WVPASSEQ(xstat.nsecs_to_timeval(-500000000), (-1, (10**9 / 2) / 1000))
        WVPASSEQ(xstat.nsecs_to_timeval(-1500000000), (-2, (10**9 / 2) / 1000))
        x = xstat.nsecs_to_timeval(1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))
        x = xstat.nsecs_to_timeval(-1977777778)
        WVPASSEQ(type(x[0]), type(0))
        WVPASSEQ(type(x[1]), type(0))

        WVPASSEQ(xstat.fstime_floor_secs(0), 0)
        WVPASSEQ(xstat.fstime_floor_secs(10**9 / 2), 0)
        WVPASSEQ(xstat.fstime_floor_secs(10**9), 1)
        WVPASSEQ(xstat.fstime_floor_secs(-10**9 / 2), -1)
        WVPASSEQ(xstat.fstime_floor_secs(-10**9), -1)
        WVPASSEQ(type(xstat.fstime_floor_secs(10**9 / 2)), type(0))
        WVPASSEQ(type(xstat.fstime_floor_secs(-10**9 / 2)), type(0))
Пример #22
0
def summary_str(meta):
    mode_val = xstat.mode_str(meta.mode)
    user_val = meta.user
    if not user_val:
        user_val = str(meta.uid)
    group_val = meta.group
    if not group_val:
        group_val = str(meta.gid)
    size_or_dev_val = '-'
    if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
        size_or_dev_val = '%d,%d' % (os.major(meta.rdev), os.minor(meta.rdev))
    elif meta.size:
        size_or_dev_val = meta.size
    mtime_secs = xstat.fstime_floor_secs(meta.mtime)
    time_val = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
    path_val = meta.path or ''
    if stat.S_ISLNK(meta.mode):
        path_val += ' -> ' + meta.symlink_target
    return '%-10s %-11s %11s %16s %s' % (mode_val, user_val + "/" + group_val,
                                         size_or_dev_val, time_val, path_val)
Пример #23
0
def summary_str(meta, numeric_ids=False, human_readable=False):
    mode_val = xstat.mode_str(meta.mode)
    user_val = meta.user
    if numeric_ids or not user_val:
        user_val = str(meta.uid)
    group_val = meta.group
    if numeric_ids or not group_val:
        group_val = str(meta.gid)
    size_or_dev_val = "-"
    if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
        size_or_dev_val = "%d,%d" % (os.major(meta.rdev), os.minor(meta.rdev))
    elif meta.size != None:
        size_or_dev_val = meta.size
        if human_readable:
            size_or_dev_val = format_filesize(meta.size)
    mtime_secs = xstat.fstime_floor_secs(meta.mtime)
    time_val = time.strftime("%Y-%m-%d %H:%M", time.localtime(mtime_secs))
    path_val = meta.path or ""
    if stat.S_ISLNK(meta.mode):
        path_val += " -> " + meta.symlink_target
    return "%-10s %-11s %11s %16s %s" % (mode_val, user_val + "/" + group_val, size_or_dev_val, time_val, path_val)
Пример #24
0
def summary_str(meta):
    mode_val = xstat.mode_str(meta.mode)
    user_val = meta.user
    if not user_val:
        user_val = str(meta.uid)
    group_val = meta.group
    if not group_val:
        group_val = str(meta.gid)
    size_or_dev_val = '-'
    if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
        size_or_dev_val = '%d,%d' % (os.major(meta.rdev), os.minor(meta.rdev))
    elif meta.size:
        size_or_dev_val = meta.size
    mtime_secs = xstat.fstime_floor_secs(meta.mtime)
    time_val = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
    path_val = meta.path or ''
    if stat.S_ISLNK(meta.mode):
        path_val += ' -> ' + meta.symlink_target
    return '%-10s %-11s %11s %16s %s' % (mode_val,
                                         user_val + "/" + group_val,
                                         size_or_dev_val,
                                         time_val,
                                         path_val)
Пример #25
0
Файл: index.py Проект: bup/bup
 def stale(self, st, tstart, check_device=True):
     if self.size != st.st_size:
         return True
     if self.mtime != st.st_mtime:
         return True
     if self.sha == EMPTY_SHA:
         return True
     if not self.gitmode:
         return True
     if self.ctime != st.st_ctime:
         return True
     if self.ino != st.st_ino:
         return True
     if self.nlink != st.st_nlink:
         return True
     if not (self.flags & IX_EXISTS):
         return True
     if check_device and (self.dev != st.st_dev):
         return True
     # Check that the ctime's "second" is at or after tstart's.
     ctime_sec_in_ns = xstat.fstime_floor_secs(st.st_ctime) * 10**9
     if ctime_sec_in_ns >= tstart:
         return True
     return False
Пример #26
0
 def stale(self, st, tstart, check_device=True):
     if self.size != st.st_size:
         return True
     if self.mtime != st.st_mtime:
         return True
     if self.sha == EMPTY_SHA:
         return True
     if not self.gitmode:
         return True
     if self.ctime != st.st_ctime:
         return True
     if self.ino != st.st_ino:
         return True
     if self.nlink != st.st_nlink:
         return True
     if not (self.flags & IX_EXISTS):
         return True
     if check_device and (self.dev != st.st_dev):
         return True
     # Check that the ctime's "second" is at or after tstart's.
     ctime_sec_in_ns = xstat.fstime_floor_secs(st.st_ctime) * 10**9
     if ctime_sec_in_ns >= tstart:
         return True
     return False
Пример #27
0
 def mtime_str(self):
     mtime_secs = xstat.fstime_floor_secs(self.mtime)
     return strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
Пример #28
0
 def __repr__(self):
     result = ["<%s instance at %s" % (self.__class__, hex(id(self)))]
     if self.path:
         result += " path:" + repr(self.path)
     if self.mode:
         result += " mode:" + repr(xstat.mode_str(self.mode) + "(%s)" % hex(self.mode))
     if self.uid:
         result += " uid:" + str(self.uid)
     if self.gid:
         result += " gid:" + str(self.gid)
     if self.user:
         result += " user:"******" group:" + repr(self.group)
     if self.size:
         result += " size:" + repr(self.size)
     for name, val in (("atime", self.atime), ("mtime", self.mtime), ("ctime", self.ctime)):
         result += " %s:%r" % (name, time.strftime("%Y-%m-%d %H:%M %z", time.gmtime(xstat.fstime_floor_secs(val))))
     result += ">"
     return "".join(result)