From 2193e1ee2f99f78d6402d23dfd68f572068268fc Mon Sep 17 00:00:00 2001 From: Brad King <brad.king@kitware.com> Date: Wed, 15 Apr 2009 13:03:33 -0400 Subject: [PATCH] BUG: Replace brittle GetParentDirectory impl The previous change to this method broke cases where the input path does not exist. The SystemTools::GetParentDirectory method is redundant with the more robust SystemTools::GetFilenamePath. This replaces its implementation to just call GetFilenamePath. --- SystemTools.cxx | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index 65f2206..6b4ad1a 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -3975,31 +3975,7 @@ bool SystemTools::SetPermissions(const char* file, mode_t mode) kwsys_stl::string SystemTools::GetParentDirectory(const char* fileOrDir) { - if ( !fileOrDir || !*fileOrDir || !SystemTools::FileExists(fileOrDir)) - { - return ""; - } - kwsys_stl::string res = fileOrDir; - SystemTools::ConvertToUnixSlashes(res); - - // If the root "/" directory is passed in, return empty string - if(strcmp(res.c_str(), "/") ==0 ) - { - return ""; - } - kwsys_stl::string::size_type cc = res.size()-1; - if ( res[cc] == '/' ) - { - cc --; - } - for ( ; cc > 0; cc -- ) - { - if ( res[cc] == '/' ) - { - break; - } - } - return res.substr(0, cc); + return SystemTools::GetFilenamePath(fileOrDir); } bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir) -- GitLab