Commit d96b49e3 authored by jan.koester's avatar jan.koester
Browse files

find tolerante

parent 942739cb
Loading
Loading
Loading
Loading
+14 −12
Changes for commands/filesystem/find.cpp: 14 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -631,24 +631,26 @@ namespace fresh { namespace cmd {
            for(; i<argc; ++i) {
                std::string a = argv[i];

                // Accept escaped GNU find parentheses.
                if(a == "\\(")
                    a = "(";
                else if(a == "\\)")
                    a = ")";

                // Some shell/build-script combinations can pass the
                // opening parenthesis attached to the first predicate:
                // "(-name" -> "(" + "-name"
                // GNU find escaped parentheses
                if(a == "\\(") {
                    p.toks.push_back("(");
                    continue;
                }

                if(a == "\\)") {
                    p.toks.push_back(")");
                    continue;
                }

                // Be tolerant of attached parentheses, e.g. "(-name"
                if(a.size() > 2 && a.rfind("(-", 0) == 0) {
                    p.toks.push_back("(");
                    p.toks.push_back(a.substr(1));
                    continue;
                }

                // Same for a closing parenthesis attached to a predicate.
                if(a.size() > 2 && a.back() == ')' &&
                a != ")") {
                // Be tolerant of "-type f)" etc.
                if(a.size() > 1 && a.back() == ')' && a != ")") {
                    p.toks.push_back(a.substr(0, a.size() - 1));
                    p.toks.push_back(")");
                    continue;