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

test

parent 724c090d
Loading
Loading
Loading
Loading
+17 −0
Changes for commands/editor/patch.cpp: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -73,6 +73,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "shell.h"

namespace {
    // mkdir -p of the directories leading to path
    void makeParents(const std::string &path){
        for(size_t i=1;i<path.size();++i){
            if(path[i]!='/')
                continue;
            std::string dir=path.substr(0,i);
            if(mkdir(dir.c_str(),0777)!=0 && errno!=EEXIST)
                return;
        }
    }
}

namespace fresh { namespace cmd {

    // One line of a hunk body: kind is ' ' (context), '-' (removed from old)
@@ -511,6 +524,10 @@ namespace fresh { namespace cmd {
                }

                const std::string &writeTo=outputFile.empty() ? target : outputFile;
                // a new file may be the first in its directory: make the
                // missing parents, as GNU patch does
                if(isCreation)
                    makeParents(writeTo);
                std::ofstream out(writeTo.c_str(),std::ios::trunc);
                if(!out.is_open()){
                    std::cerr << "patch: " << writeTo << ": " << strerror(errno) << std::endl;