Exemple #1
0
void SlashFolderLocal(Stroka &folder)
{
    if (!folder)
        return;
#ifdef _win32_
    size_t pos;
    while ((pos = folder.find('/')) != Stroka::npos)
        folder.replace(pos, 1, LOCSLASH_S);
#endif
    if (folder[+folder-1] != LOCSLASH_C)
        folder.append(LOCSLASH_S);
}
Exemple #2
0
bool PathExists(const Stroka& path) {
    VERIFY(path.find('\0') == Stroka::npos);
    return isexist(~path);
}
Exemple #3
0
int main(int argc, char** argv) {
    Opt2 opt(argc, argv, "rxcpulma:z:qo:", IntRange(1, 999999), "hexdump=x,cat=c,plain=p,unpack=u,list=l,md5=m,recursive=r,quiet=q,prepend=z,append=a,output=o");
    const bool hexdump   = opt.Has('x', "- produce hexdump");
    const bool cat       = opt.Has('c', "- do not store keys (file names), just cat uncompressed files");
    const bool doNotZip  = opt.Has('p', "- do not use compression");
    const bool unpack    = opt.Has('u', "- unpack archive in current dir");
    const bool list      = opt.Has('l', "- list files in archive");
    const bool listMd5   = opt.Has('m', "- list files in archive with md5");
    const bool recursive = opt.Has('r', "- read all files under each directory, recursively");
    Quiet                = opt.Has('q', "- do not output progress on stderr.");
    Stroka prepend = opt.Arg('z', "<PREFIX> - prepend string to output", 0);
    Stroka append  = opt.Arg('a', "<SUFFIX> - append string to output", 0);
    const Stroka outputf = opt.Arg('o', "<FILE> - output to file instead stdout", 0);
    opt.AutoUsageErr("<file>..."); // "Files or directories to archive."

    SubstGlobal(append, "\\n", "\n");
    SubstGlobal(prepend, "\\n", "\n");

    yvector<TRec> recs;
    for (size_t i = 0; i != opt.Pos.size(); ++i) {
        Stroka path = opt.Pos[i];
        size_t off = 0;
#ifdef _win_
        if (path[0] > 0 && isalpha(path[0]) && path[1] == ':')
            off = 2; // skip drive letter ("d:")
#endif // _win_
        const size_t pos = path.find(':', off);
        TRec cur;
        cur.Path = path.substr(0, pos);
        if (pos != Stroka::npos)
            cur.Prefix = path.substr(pos + 1);
        cur.Recursive = recursive;
        cur.Fix();
        recs.push_back(cur);
    }

    try {
        if (listMd5) {
            for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                ListArchiveMd5(it->Path);
            }
        } else if (list) {
            for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                ListArchive(it->Path);
            }
        } else if (unpack) {
            for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                UnpackArchive(it->Path);
            }
        } else {
            TAutoPtr<TOutputStream> outf(OpenOutput(outputf));
            TOutputStream* out = outf.Get();
            THolder<TOutputStream> hexout;

            if (hexdump) {
                hexout.Reset(new THexOutput(out));
                out = hexout.Get();
            }

            outf->Write(~prepend, +prepend);

            if (cat) {
                for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                    it->Recurse(*out);
                }
            } else {
                TArchiveWriter w(out, !doNotZip);
                for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
                    it->Recurse(w);
                }
                w.Finish();
            }

            outf->Write(~append, +append);

            try {
                out->Finish();
            } catch (...) {
            }
        }
    } catch (...) {
        Cerr << CurrentExceptionMessage() << Endl;
        return 1;
    }

    return 0;
}
Exemple #4
0
static inline bool GoodPath(const Stroka& path) {
    return path.find('/') != Stroka::npos;
}
Exemple #5
0
int main(int argc, char** argv) {
    Opt2 opt(argc, argv, "rxa:z:q", IntRange(1, 999999), "hexdump=x,recursive=r,quiet=q,prepend=z,append=a");
    bool hexdump         = opt.Has('x', "- produce hexdump");
    const bool recursive = opt.Has('r', "- read all files under each directory, recursively");
    Quiet                = opt.Has('q', "- do not output progress on stderr.");
    const Stroka prepend = opt.Arg('z', "<PREFIX> - prepend string to output verbatim", 0);
    const Stroka append  = opt.Arg('a', "<SUFFIX> - append string to output verbatim", 0);
    opt.AutoUsageErr("<file>..."); // "Files or directories to archive."

    yvector<TRec> recs;
    for (size_t i = 0; i != opt.Pos.size(); ++i) {
        Stroka path = opt.Pos[i];
        size_t off = 0;
#ifdef _win_
        if (path[0] > 0 && isalpha(path[0]) && path[1] == ':')
            off = 2; // skip drive letter ("d:")
#endif // _win_
        const size_t pos = path.find(':', off);
        TRec cur;
        cur.Path = path.substr(0, pos);
        if (pos != Stroka::npos)
            cur.Prefix = path.substr(pos + 1);
        cur.Recursive = recursive;
        cur.Fix();
        recs.push_back(cur);
    }

    try {
        TAutoPtr<TOutputStream> outf(OpenOutput(""));
        TOutputStream* out = outf.Get();
        THolder<TOutputStream> hexout;

        if (hexdump) {
            hexout.Reset(new THexOutput(out));
            out = hexout.Get();
        }

        outf->Write(~prepend, +prepend);

        TArchiveWriter w(out);

        for (yvector<TRec>::const_iterator it = recs.begin(); it != recs.end(); ++it) {
            const TRec& rec = *it;

            if (IsDir(rec.Path)) {
                it->Recurse(w);
            } else {
                Append(w, it->Path, it->Prefix + "/" + GetFile(it->Path));
            }
        }

        w.Finish();
        outf->Write(~append, +append);
        out->Finish();
    } catch (...) {
        Cerr << CurrentExceptionMessage() << Endl;

        return 1;
    }

    return 0;
}