Python源码示例:tarfile.SYMTYPE

示例1
def add(self, *, path, data, mode, islink=False):
        if path.startswith('/'):
            path = path[1:]

        tar_info = tarfile.TarInfo(name=path)
        if isinstance(data, str):
            data_bytes = data.encode('utf-8')
        else:
            data_bytes = data
        tar_info.size = len(data_bytes)
        tar_info.mode = mode
        tar_info.mtime = int(time.time())

        if tar_info.size > 0:
            # Ignore bandit false positive: B303:blacklist
            # This is a basic checksum for debugging not a secure hash.
            LOG.debug(  # nosec
                'Adding file path=%s size=%s md5=%s', path, tar_info.size,
                hashlib.md5(data_bytes).hexdigest())
        else:
            LOG.warning('Zero length file added to path=%s', path)

        if islink:
            tar_info.type = tarfile.SYMTYPE
            tar_info.linkname = data
            self._tf.addfile(tar_info)
        else:
            self._tf.addfile(tar_info, io.BytesIO(data_bytes)) 
示例2
def _convertFileType(type):
 return {
  tarfile.REGTYPE: S_IFREG,
  tarfile.LNKTYPE: S_IFLNK,
  tarfile.SYMTYPE: S_IFLNK,
  tarfile.CHRTYPE: S_IFCHR,
  tarfile.BLKTYPE: S_IFBLK,
  tarfile.DIRTYPE: S_IFDIR,
  tarfile.FIFOTYPE: S_IFIFO,
 }.get(type, S_IFREG) 
示例3
def WriteSymlink(self, src_arcname, dst_arcname):
    """Writes a symlink into the archive."""

    info = self.tar_fd.tarinfo()
    info.tarfile = self.tar_fd
    info.name = SmartStr(dst_arcname)
    info.size = 0
    info.mtime = time.time()
    info.type = tarfile.SYMTYPE
    info.linkname = SmartStr(src_arcname)

    self.tar_fd.addfile(info) 
示例4
def symlinkarchivestream(self, ticket, data_path):
        for filepath, arcpath, cont_name, cont_id, _ in ticket['target']:
            t = tarfile.TarInfo(name=arcpath)
            t.type = tarfile.SYMTYPE
            t.linkname = os.path.relpath(filepath, data_path)
            yield t.tobuf()
            self.log_user_access(AccessType.download_file, cont_name=cont_name, cont_id=cont_id, filename=os.path.basename(arcpath), multifile=True, origin_override=ticket['origin']) # log download
        stream = cStringIO.StringIO()
        with tarfile.open(mode='w|', fileobj=stream) as _:
            pass
        yield stream.getvalue() # get tar stream trailer
        stream.close()