Example #1
0
static struct tndb *do_dbopen(const char *path, int vfmode, struct vfile **vf,
                              const char *srcnam)
{
    struct vfile *vf_;
    struct tndb  *db;
    int fd;
    
    if (vf)
        *vf = NULL;
    
    if ((vf_ = vfile_open_ul(path, VFT_IO, vfmode, srcnam)) == NULL)
        return NULL;

    if ((fd = dup(vf_->vf_fd)) == -1) {
        logn(LOGERR, "dup(%d): %m", vf_->vf_fd);
        vfile_close(vf_);
        return NULL;
    }
      
    if ((db = tndb_dopen(fd, vfile_localpath(vf_))) == NULL) {
        vfile_close(vf_);

    } else {
        if (vf)
            *vf = vf_;
        else
            vfile_close(vf_);
    }
    
    return db;
}
Example #2
0
static
Header do_loadrpmhdr(const char *path, int vfmode, const char *pdir_name)
{
    struct vfile       *vf = NULL;
    tn_buf             *nbuf;
    tn_buf             buf[4096];
    int                n;
    Header             h, ch = NULL;
    
    if ((vf = vfile_open_ul(path, VFT_GZIO, vfmode, pdir_name)) == NULL)
        return NULL;

    nbuf = n_buf_new(1024 * 64);
    while ((n = gzread(vf->vf_gzstream, buf, sizeof(buf))) > 0)
        n_buf_write(nbuf, buf, n);
    vfile_close(vf);

    h = headerLoad(n_buf_ptr(nbuf)); /* rpm's memleak */
    if (h == NULL) {
        logn(LOGERR, "%s: load header failed", n_basenam(path));
        
    } else if (headerIsEntry(h, RPMTAG_SOURCEPACKAGE)) { /* omit src.rpms */
        h = NULL;
    }
    
    if (h)
        ch = headerCopy(h);
    n_buf_free(nbuf);
    return ch;
}
Example #3
0
static void repomd_ent_free(struct repomd_ent *ent)
{
    if (ent->vf) {
        vfile_close(ent->vf);
        ent->vf = NULL;
    }
    free(ent);
}
Example #4
0
static
void idx_close(struct idx *idx) 
{
    if (idx->vf)
        vfile_close(idx->vf);

    if (idx->ents)
        n_array_free(idx->ents);

    idx->vf = NULL;
    idx->ents = NULL;
}
Example #5
0
static
int open_dscr(struct pndir *idx, int vfmode, time_t ts, const char *lang)
{
    struct tndb  *db = NULL;
    struct vfile *vf = NULL;

    if (idx->db_dscr_h == NULL)
        idx->db_dscr_h = pndir_db_dscr_h_new();

    if (pndir_db_dscr_h_get(idx->db_dscr_h, lang))
        return 1;
    
    if ((db = do_open_dscr(idx, vfmode, &vf, ts, lang)) == NULL)
        return 0;

    if (tndb_verify(db)) {
        pndir_db_dscr_h_insert(idx->db_dscr_h, lang, db);
        
    } else {
        logn(LOGERR, "%s: broken file", vf_url_slim_s(tndb_path(db), 0));

        if (vf->vf_flags & VF_FRMCACHE) { /* not fully downloaded? */
            n_assert(vfmode & VFM_CACHE);
            vfmode &= ~VFM_CACHE;
            vfmode |= VFM_NODEL;
            
            tndb_close(db);
            vfile_close(vf);
            
            return open_dscr(idx, vfmode, ts, lang);
        }
        tndb_close(db);
    }
    
    if (vf)
        vfile_close(vf);
    return pndir_db_dscr_h_get(idx->db_dscr_h, lang) != NULL;
}
Example #6
0
static
int pdir_difftoc_update(const char *diffpath, const char *suffix,
                        const char *line, int line_len)
{
    char path[PATH_MAX];
    struct vfile *vf;
    int rc = 0;
        
    if (mkidx_pathname(path, sizeof(path), diffpath, suffix) == NULL)
        return 0;
    
    if ((vf = vfile_open(path, VFT_TRURLIO, VFM_APPEND))) {
        rc = (n_stream_write(vf->vf_tnstream, line, line_len) == line_len);
        vfile_close(vf);
    }
    DBGF("%s: added %s: [%s]\n", path, line, rc ? "OK" : "FAILED");
    return rc;
}
Example #7
0
void pndir_close(struct pndir *idx) 
{
    if (idx->db)
        tndb_close(idx->db);
    
    if (idx->db_dscr_h)
	n_hash_free(idx->db_dscr_h);
    
    if (idx->_vf)
        vfile_close(idx->_vf);

    if (idx->dg)
        pndir_digest_free(idx->dg);

    n_cfree(&idx->md_orig);
    n_cfree(&idx->srcnam);
    idx->_vf = NULL;
    idx->db = NULL;
    idx->dg = NULL;
    idx->idxpath[0] = '\0';
}
Example #8
0
static
int yum_update(const char *path, int vfmode, const char *sl,
               enum pkgdir_uprc *uprc)
{
    struct vfile    *vf;
    int             rc = 1;
    
    *uprc = PKGDIR_UPRC_NIL;
    if ((vf = vfile_open_ul(path, VFT_IO, vfmode, sl)) == NULL) {
        *uprc = PKGDIR_UPRC_ERR_UNKNOWN;
        return 0;
    }

    /* Download all the headers there? Probably yes, TODO */
    if (vf->vf_flags & VF_FETCHED) /* updated */
        *uprc = PKGDIR_UPRC_UPDATED;
    else
        *uprc = PKGDIR_UPRC_UPTODATE;

    vfile_close(vf);
    return rc;
}
Example #9
0
static BseErrorType
dh_vorbis_open (GslDataHandle      *dhandle,
		GslDataHandleSetup *setup)
{
  VorbisHandle *vhandle = (VorbisHandle*) dhandle;
  VFile *vfile;
  vorbis_info *vi;
  GslLong n, i;
  gint err;

  vfile = g_new0 (VFile, 1);
  vfile->rfile = gsl_rfile_open (vhandle->dhandle.name);
  if (!vfile->rfile)
    {
      g_free (vfile);
      return gsl_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED);
    }
  vfile->byte_length = gsl_rfile_length (vfile->rfile);
  if (vhandle->rfile_add_zoffset)
    {
      vfile->byte_offset = gsl_hfile_zoffset (vfile->rfile->hfile) + 1;
      vfile->byte_offset += vhandle->rfile_byte_offset;
      vfile->byte_offset = MIN (vfile->byte_offset, vfile->byte_length);
      vfile->byte_length -= vfile->byte_offset;
    }
  else
    {
      vfile->byte_offset = MIN (vhandle->rfile_byte_offset, vfile->byte_length);
      vfile->byte_length -= vfile->byte_offset;
    }
  if (vhandle->rfile_byte_length > 0)
    vfile->byte_length = MIN (vfile->byte_length, vhandle->rfile_byte_length);
  err = ov_open_callbacks (vfile, &vhandle->ofile, NULL, 0, vfile_ov_callbacks);
  if (err < 0)
    {
      if (0)
        g_printerr ("failed to open ogg at offset %d (real offset=%lld) (add-zoffset=%d): %s\n",
                    vhandle->rfile_byte_offset,
                    vfile->byte_offset,
                    vhandle->rfile_add_zoffset,
                    bse_error_blurb (ov_errno_to_error (err, BSE_ERROR_FILE_OPEN_FAILED)));
      vfile_close (vfile);
      return ov_errno_to_error (err, BSE_ERROR_FILE_OPEN_FAILED);
    }

  n = ov_streams (&vhandle->ofile);
  if (n > vhandle->bitstream)
    {
      vhandle->bitstream_serialno = ov_serialnumber (&vhandle->ofile, vhandle->bitstream);
      vhandle->n_bitstreams = n;
      if (0)
        g_printerr ("Ogg/Vorbis: opening ogg: bitstream=%d/%d serialno=%d\n", vhandle->bitstream, vhandle->n_bitstreams, vhandle->bitstream_serialno);
    }
  else
    {
      ov_clear (&vhandle->ofile); /* closes file */
      return BSE_ERROR_NO_DATA;	/* requested bitstream not available */
    }

  vhandle->soffset = 0;
  for (i = 0; i < vhandle->bitstream; i++)
    vhandle->soffset += ov_pcm_total (&vhandle->ofile, i);

  n = ov_pcm_total (&vhandle->ofile, vhandle->bitstream);
  vi = ov_info (&vhandle->ofile, vhandle->bitstream);
  if (n > 0 && vi && vi->channels && ov_pcm_seek (&vhandle->ofile, vhandle->soffset) >= 0)
    {
      setup->n_channels = vi->channels;
      setup->n_values = n * setup->n_channels;
    }
  else
    {
      ov_clear (&vhandle->ofile); /* closes file */
      return BSE_ERROR_NO_DATA;
    }

  vhandle->max_block_size = vorbis_info_blocksize (vi, 0);
  n = vorbis_info_blocksize (vi, 1);
  vhandle->max_block_size = MAX (vhandle->max_block_size, n);
  vhandle->pcm_pos = 0;
  vhandle->pcm_length = 0;
  
  setup->bit_depth = 24;
  setup->mix_freq = vi->rate;
  setup->needs_cache = TRUE;
  setup->xinfos = bse_xinfos_add_float (setup->xinfos, "osc-freq", vhandle->osc_freq);
  return BSE_ERROR_NONE;
}
Example #10
0
static
int pdir_difftoc_vacuum(const char *idxpath, const char *diffpath,
                        const char *suffix)
{
    tn_array     *lines; 
    char         line[2048], *dn, *bn, tmp[PATH_MAX];
    char         difftoc_path[PATH_MAX], difftoc_path_bak[PATH_MAX];
    struct stat  st_idx, st;
    struct vfile *vf;
    int          lineno, i, len;
    off_t        diffs_size;

    if (poldek__is_in_testing_mode())
        return 1;
    
    if (stat(idxpath, &st_idx) != 0) {
        logn(LOGERR, "vaccum diff: stat %s: %m", idxpath);
        return 0;
    }

    if (!mkidx_pathname(difftoc_path, sizeof(difftoc_path), diffpath, suffix))
        return 0;
    
    n_strncpy(tmp, difftoc_path, sizeof(tmp));
    n_basedirnam(tmp, &dn, &bn);

    
    if ((vf = vfile_open(difftoc_path, VFT_TRURLIO, VFM_RO)) == NULL)
        return 0;
    
    lines = n_array_new(128, NULL, NULL);
    while ((len = n_stream_gets(vf->vf_tnstream, line, sizeof(line))) > 0) {
        char *l;

        l = alloca(len + 1);
        memcpy(l, line, len + 1);
        n_array_push(lines, l);
        DBGF("l = [%s]\n", l);
    }
    
    if (n_array_size(lines)) {
        snprintf(difftoc_path_bak, sizeof(difftoc_path_bak), "%s-",
                 difftoc_path);
        rename(difftoc_path, difftoc_path_bak);
    }
    vfile_close(vf);

    if ((vf = vfile_open(difftoc_path, VFT_TRURLIO, VFM_RW)) == NULL) {
        rename(difftoc_path_bak, difftoc_path);
        n_array_free(lines);
        return 0;
    }
    
    lineno = 0;
    diffs_size = 0;
    for (i = n_array_size(lines) - 1; i >= 0; i--) {
        char *p, *l, path[PATH_MAX];

        l = n_array_nth(lines, i);
        if ((p = strchr(l, ' ')) == NULL) {
            logn(LOGERR, _("%s: format error"), path);
            *l = '\0';
            continue;
        }
        
        *p = '\0';
        /*                         "- 1" to save space for ".mdd" (to unlink mdd too) */
        snprintf(path, sizeof(path) - 1, "%s/%s", dn, l);

        *p = ' ';
        
        if (stat(path, &st) != 0) {
            if (errno != ENOENT)
                logn(LOGERR, "vaccum diff: stat %s: %m", l);
            *l = '\0';
            continue;
        }
        DBGF("path = (%s) %ld, %ld, %ld\n", path, st.st_size, diffs_size,
             st_idx.st_size);
        
        if (lineno) {
            if (vf_valid_path(path)) {
                char *p;
                
                msgn(1, _("Removing outdated diff %s"), n_basenam(path));
                unlink(path);
                if ((p = strrchr(path, '.')) && strcmp(p, ".gz") == 0) {
                    strcpy(p, ".mdd");
                    //msgn(1, _("Removing outdated MDD %s"), n_basenam(path));
                    unlink(path);
                }
            }
            
        } else {
            if (diffs_size + st.st_size > (st_idx.st_size * 0.9))
                lineno = i;
            else
                diffs_size += st.st_size;
        }
    }

    for (i = lineno; i < n_array_size(lines); i++) {
        char *l;
        
        l = n_array_nth(lines, i);
        if (*l)
            n_stream_printf(vf->vf_tnstream, "%s", l);
    }

    vfile_close(vf);
    n_array_free(lines);
    return 1;
}
Example #11
0
int pdir_create(struct pkgdir *pkgdir, const char *pathname,
                unsigned flags)
{
    struct vfile     *vf = NULL;
    char             path[PATH_MAX], tmp[PATH_MAX];
    char             suffix[64] = "", difftoc_suffix[256] = "";
    const char       *orig_pathname;
    int              i, nerr = 0;
    struct pdir      *idx;
    unsigned         st_flags = 0;

#if 0                           /* XXX: disabled cause to pdir_pkgdir_uniq() usage */
    if ((pkgdir->flags & PKGDIR_DIFF) && (pkgdir->flags & PKGDIR_UNIQED) == 0) {
        n_assert((flags & PKGDIR_CREAT_NOUNIQ) == 0);
        pkgdir__uniq(pkgdir);
    }
#endif
    
    idx = pkgdir->mod_data;
    if (pkgdir->ts == 0) 
        pkgdir->ts = time(0);

    if (pathname == NULL) {
        if (pkgdir->flags & PKGDIR_DIFF)
            pathname = pkgdir->orig_idxpath;
        else
            pathname = pdir_localidxpath(pkgdir);
    }
    
    n_assert(pathname);
    orig_pathname = pathname;
    
    //if ((pkgdir->flags & (PKGDIR_DIFF | PKGDIR_PATCHED)) == 0)
    //    flags |= PKGDIR_CREAT_wMD;

    
    if (pkgdir->flags & PKGDIR_DIFF) {
        char tstr[32];
        char *dn, *bn;

        strftime(tstr, sizeof(tstr), "%Y.%m.%d-%H.%M.%S",
                 gmtime(&pkgdir->orig_ts));
        
        snprintf(suffix, sizeof(suffix), ".diff.%s", tstr);
        snprintf(difftoc_suffix, sizeof(difftoc_suffix), "%s",
                 pdir_difftoc_suffix);

        memcpy(tmp, pathname, sizeof(tmp));
        n_basedirnam(tmp, &dn, &bn);
        if (!util__mksubdir(dn, pdir_packages_incdir)) {
			nerr++;
            goto l_end;
        }
        
        snprintf(path, sizeof(path), "%s/%s/%s", dn, pdir_packages_incdir, bn);
        memcpy(tmp, path, sizeof(tmp));
        pathname = tmp;
    }


    if (mkidx_pathname(path, sizeof(path), pathname, suffix) == NULL) {
        nerr++;
		goto l_end;
    }

    msgn_tty(1, _("Writing %s..."), vf_url_slim_s(path, 0));
    msgn_f(1, _("Writing %s..."), path);
    

    do_unlink(path);
    if ((vf = vfile_open(path, VFT_TRURLIO, VFM_RW)) == NULL) {
		nerr++;
		goto l_end;
    }
    
    put_fheader(vf->vf_tnstream, pdir_poldeksindex, pkgdir);
    
    
    n_stream_printf(vf->vf_tnstream, "%%%s%lu\n", pdir_tag_ts, pkgdir->ts);
    n_stream_printf(vf->vf_tnstream, "%%%s\n", pdir_tag_endvarhdr);

    if (pkgdir->flags & PKGDIR_DIFF) {
        n_stream_printf(vf->vf_tnstream, "%%%s%lu\n", pdir_tag_ts_orig,
                        pkgdir->orig_ts);

        if (pkgdir->removed_pkgs) {
            n_stream_printf(vf->vf_tnstream, "%%%s", pdir_tag_removed);
            for (i=0; i < n_array_size(pkgdir->removed_pkgs); i++) {
                struct pkg *pkg = n_array_nth(pkgdir->removed_pkgs, i);
            
                n_stream_printf(vf->vf_tnstream, "%s-", pkg->name);
                if (pkg->epoch)
                    n_stream_printf(vf->vf_tnstream, "%d:", pkg->epoch);
                n_stream_printf(vf->vf_tnstream, "%s-%s ", pkg->ver, pkg->rel);
            }
            n_stream_printf(vf->vf_tnstream, "\n");
        }
    }

    if (pkgdir->depdirs && n_array_size(pkgdir->depdirs)) {
        n_stream_printf(vf->vf_tnstream, "%%%s", pdir_tag_depdirs);
        
        for (i=0; i<n_array_size(pkgdir->depdirs); i++) {
            n_stream_printf(vf->vf_tnstream, "%s%c",
                    (char*)n_array_nth(pkgdir->depdirs, i),
                    i + 1 == n_array_size(pkgdir->depdirs) ? '\n':':');
        }
    }

    if (pkgdir->pkgroups) {
        tn_buf *nbuf = n_buf_new(8192);
        
        n_stream_printf(vf->vf_tnstream, "%%%s\n", pdir_tag_pkgroups);
        pkgroup_idx_store(pkgdir->pkgroups, nbuf);
        n_stream_write(vf->vf_tnstream, n_buf_ptr(nbuf), n_buf_size(nbuf));
        n_stream_printf(vf->vf_tnstream, "\n");
        n_buf_free(nbuf);
    }
        
    n_stream_printf(vf->vf_tnstream, "%%%s\n", pdir_tag_endhdr);

    if (pkgdir->pkgs == NULL)
        goto l_close;

    if (flags & PKGDIR_CREAT_NODESC)
        st_flags |= PKGSTORE_NODESC;

    if (flags & PKGDIR_CREAT_v018x)
        st_flags |= PKGSTORE_NOTIMESTAMP;
    //flags |= PKGDIR_CREAT_PKG_Fv017;
    //n_array_sort(pkgdir->pkgs);
    n_array_isort_ex(pkgdir->pkgs, (tn_fn_cmp)pdir_pkg_cmp);
    for (i=0; i < n_array_size(pkgdir->pkgs); i++) {
        struct pkg *pkg = n_array_nth(pkgdir->pkgs, i);

        pdir_pkg_store(pkg, vf->vf_tnstream, pkgdir->depdirs, st_flags);
#if 0                           /* debug stuff */
        if (i % 200 == 0) {
            printf("%d. ", i);
            mem_info(-10, "i");
        }
#endif        
    }
    

 l_close:
	if (vf) {
		vfile_close(vf);
		vf = NULL;
	}
	
    /* update *.diff list   */
    if (pkgdir->flags & PKGDIR_DIFF) {
        char line[1024];
        int  line_len;
        
        line_len = n_snprintf(line, sizeof(line), "%s %lu %s %lu\n", 
                              n_basenam(path), pkgdir->ts,
                              idx->mdd_orig, pkgdir->orig_ts);
        
        if (!pdir_difftoc_update(pathname, difftoc_suffix, line, line_len)) {
            nerr++;
            goto l_end;
        }
    }
    
    i = pdir_digest_create(pkgdir, path, 0); // skip .md creation,
                                             // old, old poldek  

	if (!i)
		nerr++;
    
    if (pkgdir->flags & PKGDIR_DIFF)
        pdir_difftoc_vacuum(orig_pathname, pathname, difftoc_suffix);
	
 l_end:
    return nerr == 0;
}