Python tarfile.SYMTYPE Examples

The following are 4 code examples of tarfile.SYMTYPE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tarfile , or try the search function .
Example #1
Source File: tar_bundler.py    From promenade with Apache License 2.0 5 votes vote down vote up
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)) 
Example #2
Source File: tar.py    From fwtool.py with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: grr_utils.py    From python-scripts with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #4
Source File: download.py    From core with MIT License 5 votes vote down vote up
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()