예제 #1
0
static void
listRecursive(const DirectoryPrx& dir, int depth = 0)
{
    string indent(++depth, '\t');

    NodeSeq contents = dir->list();

    for(NodeSeq::const_iterator i = contents.begin(); i != contents.end(); ++i)
    {
        DirectoryPrx dir = DirectoryPrx::checkedCast(*i);
        FilePrx file = FilePrx::uncheckedCast(*i);
        cout << indent << (*i)->name() << (dir ? " (directory):" : " (file):") << endl;
        if(dir)
        {
            listRecursive(dir, depth);
        }
        else
        {
            Lines text = file->read();
            for(Lines::const_iterator j = text.begin(); j != text.end(); ++j)
            {
                cout << indent << "\t" << *j << endl;
            }
        }
    }
}
예제 #2
0
void
Parser::destroy(const std::list<string>& names)
{
    DirectoryPrx dir = _dirs.front();

    for(std::list<string>::const_iterator i = names.begin(); i != names.end(); ++i)
    {
        if(*i == "*")
        {
            NodeDescSeq nodes = dir->list();
            for(NodeDescSeq::iterator j = nodes.begin(); j != nodes.end(); ++j)
            {
                try
                {
                    j->proxy->destroy();
                }
                catch(const PermissionDenied& ex)
                {
                    cout << "cannot remove `" << j->name << "': " << ex.reason << endl;
                }
            }
            return;
        }
        else
        {
            NodeDesc d;
            try
            {
                d = dir->find(*i);
            }
            catch(const NoSuchName&)
            {
                cout << "`" << *i << "': no such file or directory" << endl;
                return;
            }
            try
            {
                d.proxy->destroy();
            }
            catch(const PermissionDenied& ex)
            {
                cout << "cannot remove `" << *i << "': " << ex.reason << endl;
            }
        }
    }
}
예제 #3
0
void
Parser::list(const DirectoryPrx& dir, bool recursive, int depth)
{
    string indent(depth++, '\t');

    NodeDescSeq contents = dir->list();

    for(NodeDescSeq::const_iterator i = contents.begin(); i != contents.end(); ++i)
    {
        DirectoryPrx d = i->type == DirType ? DirectoryPrx::uncheckedCast(i->proxy) : (DirectoryPrx)0;
        cout << indent << i->name << (d ? " (directory)" : " (file)");
        if(d && recursive)
        {
            cout << ":" << endl;
            list(d, true, depth);
        }
        else
        {
            cout << endl;
        }
    }
}