예제 #1
0
static rc_t prepare_decompress( const compress_context * ctx,
                                KDirectory *dir, const KFile **src, KFile **dst )
{
    const KFile *temp = NULL;

    rc_t rc = KDirectoryCreateFile ( dir, dst, false, 0664, kcmInit, ctx->dst_file );
    DISP_RC( rc, "KDirectoryCreateFile() failed" );
    if ( rc != 0 ) return rc;

    rc = KDirectoryOpenFileRead ( dir, &temp, ctx->src_file );
    DISP_RC( rc, "KDirectoryOpenFileRead() failed" );
    if ( rc == 0 )
        switch( ctx->method )
        {
        case KC_GZIP : rc = KFileMakeGzipForRead ( src, temp );
                       DISP_RC( rc, "KFileMakeGzipForRead() failed" );
                       break;
        case KC_BZIP : rc = KFileMakeBzip2ForRead ( src, temp );
                       DISP_RC( rc, "KFileMakeBzip2ForRead() failed" );
                       break;
        case KC_SZIP : /* rc = KFileMakeSzipForRead ( src, temp ); */
                       rc = RC( rcExe, rcFile, rcPacking, rcFormat, rcUnknown );
                       DISP_RC( rc, "KFileMakeSzip2ForRead() failed" );
                       break;
        }
    KFileRelease ( temp );
    return rc;
}
예제 #2
0
static
rc_t KLoaderFile_Open(KLoaderFile* self)
{
    rc_t rc = 0;

    DBG(("%s opening %s\n", __func__, self->realname));
    if( (rc = KDirectoryOpenFileRead(self->dir, &self->kfile, "%s", self->realname)) == 0 ) {
        if( self->has_md5 ) {
            const KFile *md5File = NULL;
            DBG(("%s opening as md5 wrapped %s\n", __func__, self->realname));
            if( (rc = KFileMakeMD5Read(&md5File, self->file, self->md5_digest)) == 0) {
                self->file = md5File;
            }
        }
        if( rc == 0 ) {
            const KFile *z = NULL;
            switch(self->compress_type) {
                case compress_none:
                    break;
                case compress_gzip:
                    DBG(("%s opening as gzip wrapped %s\n", __func__, self->realname));
                    if( (rc = KFileMakeGzipForRead(&z, self->file)) == 0 ) {
                        KFileRelease(self->file);
                        self->file = z;
                    }
                    break;
                case compress_bzip2:
                    DBG(("%s opening as bzip2 wrapped %s\n", __func__, self->realname));
                    if( (rc = KFileMakeBzip2ForRead(&z, self->file)) == 0 ) {
                        KFileRelease(self->file);
                        self->file = z;
                    }
                    break;
                default:
                    rc = RC(rcApp, rcFile, rcOpening, rcType, rcUnexpected);
                    break;
            }
#if ! WINDOWS
            if( rc == 0 && self->ahead ) {
                const KFile *z = NULL;
                if( (rc = KQueueFileMakeRead(&z, self->pos, self->file,
                                             self->buffer_size * 10,  self->buffer_size, 0)) == 0 ) {
                    KFileRelease(self->file);
                    self->file = z;
                }
            }
#endif
        }
    }
    if( rc != 0 ) {
        PLOGERR(klogErr, (klogErr, rc, "opening $(file)", PLOG_S(file), self->filename));
        KFileRelease(self->file);
    }
    return rc;
}