Archive-Unzip-Burst

 view release on metacpan or  search on metacpan

unzip-6.0/aosvs/aosvs.c  view on Meta::CPAN


    /* last time through, might have failed opendir but returned raw wildspec */
    if (wild_dir == (DIR *)NULL) {
        notfirstcall = FALSE; /* nothing left to try--reset for new wildspec */
        if (have_dirname)
            free(dirname);
        return (char *)NULL;
    }

    /* If we've gotten this far, we've read and matched at least one entry
     * successfully (in a previous call), so dirname has been copied into
     * matchname already.
     */
    while ((file = readdir(wild_dir)) != (struct dirent *)NULL) {
        Trace((stderr, "do_wild:  readdir returns %s\n",
          FnFilter1(file->d_name)));
        if (file->d_name[0] == '.' && wildname[0] != '.')
            continue;   /* Unix:  '*' and '?' do not match leading dot */
        if (match(file->d_name, wildname, 0 WISEP)) {   /* 0 ==  case sens. */
            Trace((stderr, "do_wild:  match() succeeds\n"));
            if (have_dirname) {
                /* strcpy(matchname, dirname); */
                strcpy(matchname+dirnamelen, file->d_name);
            } else
                strcpy(matchname, file->d_name);
            return matchname;
        }
    }

    closedir(wild_dir);     /* have read at least one entry; nothing left */
    wild_dir = (DIR *)NULL;
    notfirstcall = FALSE;   /* reset for new wildspec */
    if (have_dirname)
        free(dirname);
    return (char *)NULL;

} /* end function do_wild() */

#endif /* !SFX */





/***************************/
/* Function open_outfile() */
/***************************/

int open_outfile(__G)           /* return 1 if fail */
    __GDEF
{
    int errc = 1;    /* init to show no success with AOS/VS info */
    long dmm, ddd, dyy, dhh, dmin, dss;


#ifdef DLL
    if (G.redirect_data)
        return redirect_outfile(__G)==FALSE;
#endif

    if (stat(G.filename, &G.statbuf) == 0 && unlink(G.filename) < 0) {
        Info(slide, 0x401, ((char *)slide, LoadFarString(CannotDeleteOldFile),
          FnFilter1(G.filename)));
        return 1;
    }

/*---------------------------------------------------------------------------
    If the file didn't already exist, we created it earlier.  But we just
    deleted it, which we still had to do in case we are overwriting an exis-
    ting file.  So we must create it now, again, to set the creation time
    properly.  (The creation time is the best functional approximation of
    the Unix mtime.  Really!)

    If we stored this with an AOS/VS Zip that set the extra field to contain
    the ?FSTAT packet and the ACL, we should use info from the ?FSTAT call
    now.  Otherwise (or if that fails), we should create anyway as best we
    can from the normal Zip info.

    In theory, we should look through an entire series of extra fields that
    might exist for the same file, but we're not going to bother.  If we set
    up other types of extra fields, or if other environments we run into may
    add their own stuff to existing entries in Zip files, we'll have to.

    Note that all the packet types for sys_fstat() are the same size & mostly
    have the same structure, with some fields being unused, etc.  Ditto for
    sys_create().  Thus, we assume a normal one here, not a dir/cpd or device
    or IPC file, & make little adjustments as necessary.  We will set ACLs
    later (to reduce the chance of lacking access to what we create now); note
    that for links the resolution name should be stored in the ACL field (once
    we get Zip recognizing links OK).
  ---------------------------------------------------------------------------*/

    if (G.extra_field != NULL) {
        memcpy((char *) &zzextrafld, G.extra_field, sizeof(zzextrafld));
        if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
                    sizeof(zzextrafld.extra_header_id))  &&
            !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel),
                    sizeof(zzextrafld.extra_sentinel))
        {
            zzcreatepacket.norm_create_packet.cftyp_format =
              zzextrafld.fstat_packet.norm_fstat_packet.styp_format;
            zzcreatepacket.norm_create_packet.cftyp_entry =
              zzextrafld.fstat_packet.norm_fstat_packet.styp_type;

            /* for DIRS/CPDs, the next one will give the hash frame size; for
             * IPCs it will give the port number */
            zzcreatepacket.norm_create_packet.ccps =
              zzextrafld.fstat_packet.norm_fstat_packet.scps;

            zzcreatepacket.norm_create_packet.ctim = &zztimeblock;
            zztimeblock.tcth = zzextrafld.fstat_packet.norm_fstat_packet.stch;

            /* access & modification times default to current */
            zztimeblock.tath.long_time = zztimeblock.tmth.long_time = -1;

            /* give it current process's ACL unless link; then give it
             * resolution name */
            zzcreatepacket.norm_create_packet.cacp = (char *)(-1);

            if (zzcreatepacket.norm_create_packet.cftyp_entry == $FLNK)
                zzcreatepacket.norm_create_packet.cacp = zzextrafld.aclbuf;

            zzcreatepacket.dir_create_packet.cmsh =
              zzextrafld.fstat_packet.dir_fstat_packet.scsh;
            if (zzcreatepacket.norm_create_packet.cftyp_entry != $FCPD) {
                /* element size for normal files */
                zzcreatepacket.norm_create_packet.cdel =
                  zzextrafld.fstat_packet.norm_fstat_packet.sdeh;
            }
            zzcreatepacket.norm_create_packet.cmil =
              zzextrafld.fstat_packet.norm_fstat_packet.smil;

            if ((errc = sys_create(ux_to_vs_name(vs_path, G.filename),
                 &zzcreatepacket)) != 0)
                Info(slide, 0x201, ((char *)slide,
                  "error creating %s with AOS/VS info -\n\
                  will try again with ordinary Zip info\n",
                  FnFilter1(G.filename)));
        }
    }

    /* do it the hard way if no AOS/VS info was stored or if we had problems */
    if (errc) {
        /* skip restoring time stamps on user's request */



( run in 2.537 seconds using v1.01-cache-2.11-cpan-364913b4093 )