コード例 #1
0
ファイル: helpers.py プロジェクト: yask123/merge
 def test_bigint(self):
     self.assert_equal(int_to_bigint(0), 0)
     self.assert_equal(int_to_bigint(2**63-1), 2**63-1)
     self.assert_equal(int_to_bigint(-2**63+1), -2**63+1)
     self.assert_equal(int_to_bigint(2**63), b'\x00\x00\x00\x00\x00\x00\x00\x80\x00')
     self.assert_equal(int_to_bigint(-2**63), b'\x00\x00\x00\x00\x00\x00\x00\x80\xff')
     self.assert_equal(bigint_to_int(int_to_bigint(-2**70)), -2**70)
     self.assert_equal(bigint_to_int(int_to_bigint(2**70)), 2**70)
コード例 #2
0
 def test_bigint(self):
     self.assert_equal(int_to_bigint(0), 0)
     self.assert_equal(int_to_bigint(2**63 - 1), 2**63 - 1)
     self.assert_equal(int_to_bigint(-2**63 + 1), -2**63 + 1)
     self.assert_equal(int_to_bigint(2**63),
                       b'\x00\x00\x00\x00\x00\x00\x00\x80\x00')
     self.assert_equal(int_to_bigint(-2**63),
                       b'\x00\x00\x00\x00\x00\x00\x00\x80\xff')
     self.assert_equal(bigint_to_int(int_to_bigint(-2**70)), -2**70)
     self.assert_equal(bigint_to_int(int_to_bigint(2**70)), 2**70)
コード例 #3
0
 def do_list(self, args):
     """List archive or repository contents"""
     repository = self.open_repository(args.src)
     manifest, key = Manifest.load(repository)
     if args.src.archive:
         tmap = {1: 'p', 2: 'c', 4: 'd', 6: 'b', 0o10: '-', 0o12: 'l', 0o14: 's'}
         archive = Archive(repository, key, manifest, args.src.archive)
         for item in archive.iter_items():
             type = tmap.get(item[b'mode'] // 4096, '?')
             mode = format_file_mode(item[b'mode'])
             size = 0
             if type == '-':
                 try:
                     size = sum(size for _, size, _ in item[b'chunks'])
                 except KeyError:
                     pass
             mtime = format_time(datetime.fromtimestamp(bigint_to_int(item[b'mtime']) / 1e9))
             if b'source' in item:
                 if type == 'l':
                     extra = ' -> %s' % item[b'source']
                 else:
                     type = 'h'
                     extra = ' link to %s' % item[b'source']
             else:
                 extra = ''
             print('%s%s %-6s %-6s %8d %s %s%s' % (type, mode, item[b'user'] or item[b'uid'],
                                               item[b'group'] or item[b'gid'], size, mtime,
                                               remove_surrogates(item[b'path']), extra))
     else:
         for archive in sorted(Archive.list_archives(repository, key, manifest), key=attrgetter('ts')):
             print(format_archive(archive))
     return self.exit_code
コード例 #4
0
 def do_list(self, args):
     """List archive or repository contents"""
     repository = self.open_repository(args.src)
     manifest, key = Manifest.load(repository)
     if args.src.archive:
         tmap = {
             1: 'p',
             2: 'c',
             4: 'd',
             6: 'b',
             0o10: '-',
             0o12: 'l',
             0o14: 's'
         }
         archive = Archive(repository, key, manifest, args.src.archive)
         for item in archive.iter_items():
             type = tmap.get(item[b'mode'] // 4096, '?')
             mode = format_file_mode(item[b'mode'])
             size = 0
             if type == '-':
                 try:
                     size = sum(size for _, size, _ in item[b'chunks'])
                 except KeyError:
                     pass
             mtime = format_time(
                 datetime.fromtimestamp(
                     bigint_to_int(item[b'mtime']) / 1e9))
             if b'source' in item:
                 if type == 'l':
                     extra = ' -> %s' % item[b'source']
                 else:
                     type = 'h'
                     extra = ' link to %s' % item[b'source']
             else:
                 extra = ''
             print('%s%s %-6s %-6s %8d %s %s%s' %
                   (type, mode, item[b'user']
                    or item[b'uid'], item[b'group'] or item[b'gid'], size,
                    mtime, remove_surrogates(item[b'path']), extra))
     else:
         for archive in sorted(Archive.list_archives(
                 repository, key, manifest),
                               key=attrgetter('ts')):
             print(format_archive(archive))
     return self.exit_code
コード例 #5
0
ファイル: archive.py プロジェクト: aykit/borg
 def restore_attrs(self, path, item, symlink=False, fd=None):
     xattrs = item.get(b'xattrs')
     if xattrs:
             for k, v in xattrs.items():
                 try:
                     xattr.setxattr(fd or path, k, v, follow_symlinks=False)
                 except OSError as e:
                     if e.errno != errno.ENOTSUP:
                         raise
     uid = gid = None
     if not self.numeric_owner:
         uid = user2uid(item[b'user'])
         gid = group2gid(item[b'group'])
     uid = item[b'uid'] if uid is None else uid
     gid = item[b'gid'] if gid is None else gid
     # This code is a bit of a mess due to os specific differences
     try:
         if fd:
             os.fchown(fd, uid, gid)
         else:
             os.lchown(path, uid, gid)
     except OSError:
         pass
     if fd:
         os.fchmod(fd, item[b'mode'])
     elif not symlink:
         os.chmod(path, item[b'mode'])
     elif has_lchmod:  # Not available on Linux
         os.lchmod(path, item[b'mode'])
     mtime = bigint_to_int(item[b'mtime'])
     if fd and utime_supports_fd:  # Python >= 3.3
         os.utime(fd, None, ns=(mtime, mtime))
     elif utime_supports_follow_symlinks:  # Python >= 3.3
         os.utime(path, None, ns=(mtime, mtime), follow_symlinks=False)
     elif not symlink:
         os.utime(path, (mtime / 1e9, mtime / 1e9))
     acl_set(path, item, self.numeric_owner)
     # Only available on OS X and FreeBSD
     if has_lchflags and b'bsdflags' in item:
         try:
             os.lchflags(path, item[b'bsdflags'])
         except OSError:
             pass
コード例 #6
0
ファイル: archive.py プロジェクト: nonsub/attic
 def restore_attrs(self, path, item, symlink=False, fd=None):
     xattrs = item.get(b'xattrs')
     if xattrs:
         for k, v in xattrs.items():
             try:
                 xattr.setxattr(fd or path, k, v, follow_symlinks=False)
             except OSError as e:
                 if e.errno != errno.ENOTSUP:
                     raise
     uid = gid = None
     if not self.numeric_owner:
         uid = user2uid(item[b'user'])
         gid = group2gid(item[b'group'])
     uid = item[b'uid'] if uid is None else uid
     gid = item[b'gid'] if gid is None else gid
     # This code is a bit of a mess due to os specific differences
     try:
         if fd:
             os.fchown(fd, uid, gid)
         else:
             os.lchown(path, uid, gid)
     except OSError:
         pass
     if fd:
         os.fchmod(fd, item[b'mode'])
     elif not symlink:
         os.chmod(path, item[b'mode'])
     elif has_lchmod:  # Not available on Linux
         os.lchmod(path, item[b'mode'])
     mtime = bigint_to_int(item[b'mtime'])
     if fd and utime_supports_fd:  # Python >= 3.3
         os.utime(fd, None, ns=(mtime, mtime))
     elif utime_supports_follow_symlinks:  # Python >= 3.3
         os.utime(path, None, ns=(mtime, mtime), follow_symlinks=False)
     elif not symlink:
         os.utime(path, (mtime / 1e9, mtime / 1e9))
     acl_set(path, item, self.numeric_owner)
     # Only available on OS X and FreeBSD
     if has_lchflags and b'bsdflags' in item:
         try:
             os.lchflags(path, item[b'bsdflags'])
         except OSError:
             pass