Ejemplo n.º 1
0
static
rc_t CC extract_action (const KDirectory * dir, const char * path, void * _adata)
{
    rc_t            rc;
    extract_adata * adata;
    KPathType     type;
    char            link	[2 * 4096]; /* we'll truncate? */
    uint32_t	    access;
    rc = 0;
    adata = _adata;

    STSMSG (1, ("extract_action: %s\n", path));

    type = KDirectoryPathType (dir, path);

    if (type & kptAlias)
    {
        rc = KDirectoryVResolveAlias (dir, false, link, sizeof (link),
                                      path, NULL);
        if (rc == 0)
        {
            rc = KDirectoryVAccess (dir, &access, path, NULL);
            if (rc == 0)
            {
                rc = KDirectoryCreateAlias (adata->dir, access, kcmCreate|kcmParents,
                                            link, path);
            }
        }
    }
    else
    {
        switch (type & ~kptAlias)
        {
        case kptNotFound:
            rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcNotFound);

            KOutMsg ("%s: %s type kptNotFouns %R\n", __func__, path, rc);

            break;
        case kptBadPath:
            rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcInvalid);
            break;
        case kptFile:
            rc = KDirectoryVAccess (dir, &access, path, NULL);
            if (rc == 0)
            {
                const KFile * fin;
                KFile * fout;
                rc = KDirectoryVCreateFile (adata->dir, &fout, false, access,
                                            kcmCreate|kcmParents,
                                            path, NULL);
                if (rc == 0)
                {
                    rc = KDirectoryVOpenFileRead (dir, &fin, path, NULL);
                    if (rc == 0)
                    {
#if USE_SKEY_MD5_FIX
                        /* KLUDGE!!!! */
                        size_t pathz, skey_md5z;
                        static const char skey_md5[] = "skey.md5";

                        pathz = string_size (path);
                        skey_md5z = string_size(skey_md5);
                        if ( pathz >= skey_md5z && strcmp ( & path [ pathz - skey_md5z ], skey_md5 ) == 0 )
                            rc = copy_file_skey_md5_kludge (fin, fout);
                        else
#endif
                            rc = copy_file (fin, fout);
                        KFileRelease (fin);
                    }
                    KFileRelease (fout);
                }
            }
            break;
        case kptDir:
            rc = KDirectoryVAccess (dir, &access, path, NULL);
            if (rc == 0)
            {
                rc = KDirectoryCreateDir (adata->dir, 0700, 
                                          kcmCreate|kcmParents,
                                          path, NULL);
                if (rc == 0)
                {
                    rc = step_through_dir (dir, path, adata->filter, adata->fdata,
                                           extract_action, adata);
                    if (rc == 0)
                        rc = KDirectoryVSetAccess (adata->dir, false, access, 0777, path, NULL);
                }



            }
            break;
        case kptCharDev:
        case kptBlockDev:
        case kptFIFO:
            /* shouldn't get here */
            return 0;
        }
    }

    return rc;
}
Ejemplo n.º 2
0
 /* CreateAlias
 *  creates a path alias according to create mode
 *
 *  "access" [ IN ] - standard Unix directory access mode
 *  used when "mode" has kcmParents set and alias path does
 *  not exist.
 *
 *  "mode" [ IN ] - a creation mode ( see explanation above ).
 *
 *  "targ" [ IN ] - NUL terminated string in directory-native
 *  character set denoting target object
 *
 *  "alias" [ IN ] - NUL terminated string in directory-native
 *  character set denoting target alias
 */
 inline rc_t CreateAlias ( uint32_t access, KCreateMode mode,
    const char *targ, const char *alias ) throw ()
 { return KDirectoryCreateAlias ( this, access, mode, targ, alias ); }