From 11903063211dc368d03f52e090e52ab18ebe3f47 Mon Sep 17 00:00:00 2001 From: marha Date: Thu, 27 Jan 2011 13:44:12 +0000 Subject: Implemented mkdir as an internal command --- tools/mhmake/src/build.cpp | 27 ++++++++++++++++++++++++--- tools/mhmake/src/fileinfo.cpp | 9 ++++++++- tools/mhmake/src/fileinfo.h | 9 +++++++-- tools/mhmake/src/mhmakefileparser.cpp | 22 ++++++++-------------- tools/mhmake/src/mhmakefileparser.h | 1 + tools/mhmake/src/util.cpp | 17 +++++++++++++++++ tools/mhmake/src/util.h | 3 ++- 7 files changed, 67 insertions(+), 21 deletions(-) diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp index d1c4a32d1..36fdefb3d 100644 --- a/tools/mhmake/src/build.cpp +++ b/tools/mhmake/src/build.cpp @@ -357,7 +357,7 @@ exit: Error = false; goto exit; } - if (-1==mkdir(pNewDest->GetFullFileName().c_str(),0777)) + if (-1==mkdir(pNewDest->GetFullFileName().c_str(),S_IRWXU)) { cerr << "Error creating directory " << pNewDest->GetQuotedFullFileName() << endl; Error = false; @@ -382,6 +382,23 @@ exit: return Error; } +/*****************************************************************************/ +mh_pid_t mhmakefileparser::MakeDirsCommand(const string &Params) const +{ + vector Dirs; + + SplitToItems(Params,Dirs); + + size_t NrDirs=Dirs.size(); + for (size_t i=0; iMINPATHLENGTH && m_AbsFileName[m_AbsFileName.length()-1]==OSPATHSEP) m_AbsFileName.resize(m_AbsFileName.length()-1); } diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp index cf41b3c1c..b198c1ca8 100644 --- a/tools/mhmake/src/mhmakefileparser.cpp +++ b/tools/mhmake/src/mhmakefileparser.cpp @@ -804,19 +804,6 @@ void mhmakefileparser::LoadAutoDepsFile(fileinfo *pDepFile) fclose(pIn); } -static void MakeDirs(const fileinfo *pDir) -{ - fileinfo *pParentDir=pDir->GetDir(); - if (!pParentDir->GetDate().DoesExist()) - { /* First make parent dirs */ - MakeDirs(pParentDir); - } - if (!pDir->GetDate().DoesExist()) - { /* Create directory */ - mkdir(pDir->GetFullFileName().c_str(),S_IRWXU); - } -} - void mhmakefileparser::SaveAutoDepsFile() { if (!IsAutoDepsDirty()) @@ -845,7 +832,14 @@ void mhmakefileparser::SaveAutoDepsFile() if (!pOut) { /* Maybe it is because the directory does not exist, so try to create this first */ - MakeDirs(pDepFile->GetDir()); + if (!MakeDirs(pDepFile->GetDir())) + { + #ifdef _DEBUG + if (!g_DoNotExecute) + #endif + cerr << "Error creating dir "<GetDir()->GetFullFileName()<GetFullFileName().c_str(),"wb"); if (!pOut) diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h index 9f6cb5a96..581d243b0 100644 --- a/tools/mhmake/src/mhmakefileparser.h +++ b/tools/mhmake/src/mhmakefileparser.h @@ -381,6 +381,7 @@ public: mh_pid_t CopyFiles(const string &Params) const; mh_pid_t TouchFiles(const string &Params) const; mh_pid_t EchoCommand(const string &Params) const; + mh_pid_t MakeDirsCommand(const string &Params) const; string SearchCommand(const string &Command, const string &Extension="") const; const string &GetPythonExe() const; int SearchPath(const char *szCommand, const char *pExt, size_t Len, char *szFullCommand,char **pFilePart) const; diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp index 9b34b41ea..46f9b9edb 100644 --- a/tools/mhmake/src/util.cpp +++ b/tools/mhmake/src/util.cpp @@ -746,6 +746,23 @@ void loadedmakefile::LoadMakefile() } } +/*****************************************************************************/ +bool MakeDirs(const fileinfo *pDir) +{ + fileinfo *pParentDir=pDir->GetDir(); + if (!pParentDir->GetDate().DoesExist()) + { /* First make parent dirs */ + if (!MakeDirs(pParentDir)) + return false; + } + if (!pDir->GetDate().DoesExist()) + { /* Create directory */ + if (-1==mkdir(pDir->GetFullFileName().c_str(),S_IRWXU)) + return false; + } + return true; +} + #ifdef _DEBUG /////////////////////////////////////////////////////////////////////////////// void DumpVarsAndRules() diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h index 069effc07..aba9ec649 100644 --- a/tools/mhmake/src/util.h +++ b/tools/mhmake/src/util.h @@ -50,7 +50,7 @@ #define PLATFORM "linux" #endif -#define MHMAKEVER "2.3.30" +#define MHMAKEVER "2.4.1" class makecommand { @@ -232,6 +232,7 @@ public: extern LOADEDMAKEFILES g_LoadedMakefiles; +bool MakeDirs(const fileinfo *pDir); // Creates a directory tree void DumpVarsAndRules(); #endif -- cgit v1.2.3