ENH: Add untaring support
This commit is contained in:
parent
21c7454250
commit
d1180fc4e1
@ -1382,7 +1382,7 @@ bool cmSystemTools::CreateTar(const char* outFileName, const std::vector<cmStdSt
|
|||||||
TAR_VERBOSE
|
TAR_VERBOSE
|
||||||
| 0) == -1)
|
| 0) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "tar_open(): %s\n", strerror(errno));
|
cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1395,9 +1395,10 @@ bool cmSystemTools::CreateTar(const char* outFileName, const std::vector<cmStdSt
|
|||||||
buf[sizeof(buf)-1] = 0;
|
buf[sizeof(buf)-1] = 0;
|
||||||
if (tar_append_tree(t, buf, pathname) != 0)
|
if (tar_append_tree(t, buf, pathname) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
cmOStringStream ostr;
|
||||||
"tar_append_tree(\"%s\", \"%s\"): %s\n", buf,
|
ostr << "Problem with tar_append_tree(\"" << buf << "\", \"" << pathname << "\"): "
|
||||||
pathname, strerror(errno));
|
<< strerror(errno);
|
||||||
|
cmSystemTools::Error(ostr.str().c_str());
|
||||||
tar_close(t);
|
tar_close(t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1405,14 +1406,53 @@ bool cmSystemTools::CreateTar(const char* outFileName, const std::vector<cmStdSt
|
|||||||
|
|
||||||
if (tar_append_eof(t) != 0)
|
if (tar_append_eof(t) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "tar_append_eof(): %s\n", strerror(errno));
|
cmSystemTools::Error("Problem with tar_append_eof(): ", strerror(errno));
|
||||||
tar_close(t);
|
tar_close(t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tar_close(t) != 0)
|
if (tar_close(t) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "tar_close(): %s\n", strerror(errno));
|
cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmSystemTools::ExtractTar(const char* outFileName, const std::vector<cmStdString>& files)
|
||||||
|
{
|
||||||
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
TAR *t;
|
||||||
|
// Ok, this libtar is not const safe. for now use auto_ptr hack
|
||||||
|
char* realName = new char[ strlen(outFileName) + 1 ];
|
||||||
|
std::auto_ptr<char> realNamePtr(realName);
|
||||||
|
strcpy(realName, outFileName);
|
||||||
|
if (tar_open(&t, realName,
|
||||||
|
NULL,
|
||||||
|
O_RDONLY
|
||||||
|
#ifdef _WIN32
|
||||||
|
| O_BINARY
|
||||||
|
#endif
|
||||||
|
, 0,
|
||||||
|
TAR_VERBOSE
|
||||||
|
| 0) == -1)
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tar_extract_all(t, 0) != 0)
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("Problem with tar_extract_all(): ", strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tar_close(t) != 0)
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -299,6 +299,7 @@ public:
|
|||||||
|
|
||||||
/** Create tar */
|
/** Create tar */
|
||||||
static bool CreateTar(const char* outFileName, const std::vector<cmStdString>& files);
|
static bool CreateTar(const char* outFileName, const std::vector<cmStdString>& files);
|
||||||
|
static bool ExtractTar(const char* inFileName, const std::vector<cmStdString>& files);
|
||||||
private:
|
private:
|
||||||
static bool s_ForceUnixPaths;
|
static bool s_ForceUnixPaths;
|
||||||
static bool s_RunCommandHideConsole;
|
static bool s_RunCommandHideConsole;
|
||||||
|
@ -963,6 +963,23 @@ int cmake::CMakeCommand(std::vector<std::string>& args)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Untar files
|
||||||
|
else if (args[1] == "untar" && args.size() > 3)
|
||||||
|
{
|
||||||
|
std::string outFile = args[2];
|
||||||
|
std::vector<cmStdString> files;
|
||||||
|
for (std::string::size_type cc = 3; cc < args.size(); cc ++)
|
||||||
|
{
|
||||||
|
files.push_back(args[cc]);
|
||||||
|
}
|
||||||
|
if ( !cmSystemTools::ExtractTar(outFile.c_str(), files) )
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
// Internal CMake Fortran module support.
|
// Internal CMake Fortran module support.
|
||||||
else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
|
else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user