Exemple #1
0
static
rc_t run()
{
    KDirectory * pwd;
    const KDirectory * xfs;
    const KFile * xml;
    rc_t rc;

    STSMSG (1, ("Open file system\n"));
    rc = KDirectoryNativeDir (&pwd);
    if (rc)
        LOGERR (klogErr, rc, "Failed to open filesystem");
    else
    {
        STSMSG (1, ("Open file %s\n", XML));
        rc = KDirectoryOpenFileRead (pwd, &xml, XML);
        if (rc)
            LOGERR (klogErr, rc, "failed to open xml file");
        else
        {
            STSMSG (1, ("Open chrooted as XML TOC %s\n", BASE));
            rc = KDirectoryOpenXTocDirRead (pwd, &xfs, true, xml, BASE);
            if (rc)
                LOGERR (klogErr, rc, "Failed to open xfs directory");
            else
            {
                size_t pz;
                char path [8192];

                rc = KDirectoryResolvePath (xfs, false, path, sizeof path, INNER_FILE1);
                if (rc == 0)
                {
                    OUTMSG (("path is '%s'\n", path));

                    rc = KDirectoryResolvePath (xfs, false, path, sizeof path, INNER_FILE2);
                    if (rc == 0)
                    {
                        OUTMSG (("path is '%s'\n", path));

                        rc = KDirectoryResolvePath (xfs, true, path, sizeof path, INNER_FILE1);
                        if (rc == 0)
                        {
                            OUTMSG (("path is '%s'\n", path));

                            rc = KDirectoryResolvePath (xfs, true, path, sizeof path, INNER_FILE2);
                            if (rc == 0)
                            {
                                OUTMSG (("path is '%s'\n", path));
                            }
                        }
                    }
                }

                KDirectoryRelease (xfs);
            }
            if (rc == 0)
            {
                STSMSG (1, ("Open as XML TOC %s\n", BASE));
                rc = KDirectoryOpenXTocDirRead (pwd, &xfs, false, xml, BASE);
                if (rc)
                    LOGERR (klogErr, rc, "Failed to open xfs directory");
                else
                {
                    size_t pz;
                    char path [8192];

                    rc = KDirectoryResolvePath (xfs, false, path, sizeof path, INNER_FILE1);
                    if (rc == 0)
                    {
                        OUTMSG (("path is '%s'\n", path));

                        rc = KDirectoryResolvePath (xfs, false, path, sizeof path, INNER_FILE2);
                        if (rc == 0)
                        {
                            OUTMSG (("path is '%s'\n", path));

                            rc = KDirectoryResolvePath (xfs, true, path, sizeof path, INNER_FILE1);
                            if (rc == 0)
                            {
                                OUTMSG (("path is '%s'\n", path));

                                rc = KDirectoryResolvePath (xfs, true, path, sizeof path, INNER_FILE2);
                                if (rc == 0)
                                {
                                    OUTMSG (("path is '%s'\n", path));
                                }
                            }
                        }
                    }
                    KDirectoryRelease (xfs);
                }
            }
            KFileRelease (xml);
        }
        KDirectoryRelease (pwd);
    }
    return rc;
}
Exemple #2
0
/*  ----------------------------------------------------------------------
 * SCHEME:PATH/FILE?QUERY
 *
 * form_one is just a file
 * form_two is just a path and a file (can ignore scheme until more schemes supported)
 * form_three is all parts except path present which for here acts like form_one
 * form_four is all four parts
 *
 * path is the directory path leading to root
 * root will be the directory containing the archive
 * base will be the archive as a directory
 */
static
rc_t open_root_then_run ()
{
    static const char dot[] = ".";
    char         rootstr [8192];
    char         basestr [8192];
    const char * colon;
    rc_t rc;

    colon = strchr (options.arcstr, ':');
    if (colon == NULL) /* no scheme so it has to be a plain path */
    {
        char * last_slash;

        strcpy (basestr, options.arcstr);
        last_slash = strrchr (basestr, '/');

        if (last_slash == NULL) /* in this directory */
        {
            options.rootstr = dot;
            options.basestr = options.arcstr;
            /* done */
        }
        else
        {
            *last_slash = '\0';
            options.rootstr = basestr;
            options.basestr = last_slash + 1;
            /* done */
        }
    }
    else
    {
        char * end_of_root;
        char * last_slash;

        strcpy (rootstr, colon+1);

        end_of_root = strchr (rootstr, '?');

        if (end_of_root == NULL)
            end_of_root = strchr (rootstr, '#');

        if (end_of_root)
            *end_of_root = '\0';

        options.rootstr = rootstr;

        last_slash = strchr (rootstr, '/');
        if (last_slash == NULL)
        {
            /* no path */
            options.rootstr = dot;
            options.basestr = options.arcstr;
            /* done */
        }
        else
        {
            size_t x,z;

            *last_slash = '\0';
            options.rootstr = rootstr;

            /* scheme */
            z = string_size (rootstr);

            x = string_copy (basestr, sizeof (basestr), options.arcstr, (colon + 1) - options.arcstr);
            strcpy (basestr + x, options.arcstr + x + z + 1);
            options.basestr = basestr;
            /* done */
        }
    }
    {
        KDirectory * cwd;

        rc = VFSManagerGetCWD (options.vfsmgr, &cwd);
        if (rc)
            ;
        else
        {
            rc = KDirectoryOpenXTocDirRead (cwd, &options.root, true,
                                            options.xml, "%s", options.rootstr);
            if (rc)
                PLOGERR (klogErr, (klogErr, rc,
                                   "failed to open XFS from '$(P)' using '$(P)'",
                                   "P=%s", options.basestr, options.xmlstr));
            else
            {
                rc = VFSManagerMakePath (options.vfsmgr, &options.basepath, "%s", options.basestr);
                if (rc)
                    PLOGERR (klogErr, (klogErr, rc,
                                       "failed to make vpath from '$(P)'",
                                       "P=%s", options.basestr));
                else
                {
                    rc = VFSManagerOpenDirectoryRead (options.vfsmgr,
                                                      &options.base,
                                                      options.basepath);
                    if (rc == 0)
                    {
                        rc = build_vpath_then_run ();

                        KDirectoryRelease (options.base);
                    }
                    KDirectoryRelease (options.root);
                }
                VPathRelease (options.basepath);
            }
            KDirectoryRelease (cwd);
        }
    }
    return rc;
}
Exemple #3
0
static
rc_t run(bool compressed)
{
    KDirectory * pwd;
    const KDirectory * xfs;
    const KFile * xml;
    rc_t rc;

    STSMSG (1, ("Open file system\n"));
    rc = KDirectoryNativeDir (&pwd);
    if (rc)
        LOGERR (klogErr, rc, "Failed to open filesystem");
    else
    {
        const char* cc_xml = "test-xfs/compressed.xml";
        if (!compressed)
        {   cc_xml = "test-xfs/uncompressed.xml"; }
        STSMSG (1, ("Open file %s\n", cc_xml));
        rc = KDirectoryOpenFileRead(pwd, &xml, cc_xml);
        if (rc)
        {   LOGERR(klogErr, rc, "failed to open xml file"); }
        else
        {
            const char* src = "test-xfs/compressed.tgz";
            if (!compressed)
            {   src = "test-xfs/uncompressed/"; }
            STSMSG(1, ("Open as XML TOC %s\n", src));
            rc = KDirectoryOpenXTocDirRead(pwd, &xfs, true, xml, src);
            if (rc)
                LOGERR (klogErr, rc, "Failed to open xfs directory");
            else
            {
                const char name[] = "compressed.tgz/compressed.tar/dir/file";
                const KFile * afile;
                STSMSG (1, ("Open file %s\n", name));
                rc = KDirectoryOpenFileRead (xfs, &afile, name);
                if (rc)
                    LOGERR (klogErr, rc, "failed to open inner most file");
                else
                {
                  uint64_t pos = 0;
                  while (true) {
                    char b[1024];
                    size_t z;

                    rc = KFileRead (afile, pos, b, sizeof (b), &z);
                    if (rc == 0) {
                        b[z] = 0;
                        KOutMsg ("%s", b);
                        if (z == 0) {
                            KOutMsg ("EOF: %zu bytes\n", pos);
                            break;
                        }
                        pos += z;
                    }
                    else {
                        LOGERR (klogErr, rc, "Failed to read");
                        break;
                    }
                  }
                  STSMSG (2, ("Closing file %s\n", name));
                  KFileRelease (afile);
                }
                KDirectoryRelease (xfs);
            }

            KFileRelease (xml);
        }
        KDirectoryRelease (pwd);
    }
    return rc;
}