浏览代码

BUG: the directory the FILE DOWNLOAD command is writing to might not exist.

Sebastien Barre 17 年之前
父节点
当前提交
cddb1346b7
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      Source/cmFileCommand.cxx

+ 11 - 0
Source/cmFileCommand.cxx

@@ -2060,6 +2060,17 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string>
       }
     i++;
     }
+
+  std::string dir = cmSystemTools::GetFilenamePath(file.c_str());
+  if(!cmSystemTools::FileExists(dir.c_str()) &&
+     !cmSystemTools::MakeDirectory(dir.c_str()))
+    {
+    std::string errstring = "FILE(DOWNLOAD ) error; cannot create directory: "
+      + dir + ". Maybe need administrative privileges.";
+    this->SetError(errstring.c_str());
+    return false;
+    }
+
   std::ofstream fout(file.c_str(), std::ios::binary);
   if(!fout)
     {