def __init__(self, f, mode='r', format=None, thread_synchronize=True): """Create a FS that maps on to an archive file. :param f: a (system) path, or a file-like object :param format: required for 'w' mode. The archive format ('zip, 'tar', etc) :param thread_synchronize: set to True (default) to enable thread-safety """ super(ArchiveFS, self).__init__(thread_synchronize=thread_synchronize) if isinstance(f, str): self.fileobj = None self.root_path = f else: self.fileobj = f self.root_path = getattr(f, 'name', None) self.contents = PathMap() self.archive = libarchive.SeekableArchive(f, format=format, mode=mode) if 'r' in mode: for item in self.archive: for part in recursepath(item.pathname)[1:]: part = relpath(part) if part == item.pathname: self.contents[part] = item else: self.contents[part] = libarchive.Entry( pathname=part, mode=stat.S_IFDIR, size=0, mtime=item.mtime)
def make_entry(f, base_path): entry = libarchive.Entry(encoding='utf-8') st = os.stat(f) entry.pathname = base_path entry.size = st.st_size entry.mtime = st.st_mtime entry.mode = st.st_mode return entry
def make_entry(self, f, base_path): sftp = self.get_sftp_connection(self.session) entry = libarchive.Entry(encoding='utf-8') st = sftp.stat(f) entry.pathname = base_path entry.size = st.st_size entry.mtime = st.st_mtime entry.mode = st.st_mode return entry