How to use the ratarmount.StenciledFile function in ratarmount

To help you get started, we’ve selected a few ratarmount examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mxmlnkn / ratarmount / ratarmount.py View on Github external
targetLink = '/' + fileInfo.linkname.lstrip( '/' )
            if targetLink != path:
                return self.read( targetLink, length, offset, fh )

        # Handle access to underlying non-empty folder
        if isinstance( mountSource, str ):
            f = open( mountSource, 'rb' )
            f.seek( offset )
            return f.read( length )

        if fileInfo.issparse:
            # The TAR file format is very simple. It's just a concatenation of TAR blocks. There is not even a
            # global header, only the TAR block headers. That's why we can simpley cut out the TAR block for
            # the sparse file using StenciledFile and then use tarfile on it to expand the sparse file correctly.
            tarBlockSize = fileInfo.offset - fileInfo.offsetheader + fileInfo.size
            tarSubFile = StenciledFile( mountSource.tarFileObject, [ ( fileInfo.offsetheader, tarBlockSize ) ] )
            tmpTarFile = tarfile.open( fileobj = tarSubFile, mode = 'r:' )
            tmpFileObject = tmpTarFile.extractfile( next( iter( tmpTarFile ) ) )
            tmpFileObject.seek( offset, os.SEEK_SET )
            result = tmpFileObject.read( length )
            tmpTarFile.close()
            return result

        try:
            mountSource.tarFileObject.seek( fileInfo.offset + offset, os.SEEK_SET )
            return mountSource.tarFileObject.read( length )
        except RuntimeError as e:
            traceback.print_exc()
            print( "Caught exception when trying to read data from underlying TAR file! Returning errno.EIO." )
            raise fuse.FuseOSError( fuse.errno.EIO )