Commit 22216d56 authored by Jack Guo's avatar Jack Guo Committed by Brad King
Browse files

SystemTools: Fix Touch() on broken symlink when create==false

The `touch -c` command-line tool does nothing when given a broken
symlink.  Fix `SystemTools::Touch` to do the same.

This was broken by commit 45db0937 (SystemTools: use PathExists where
appropriate, 2017-01-10).
parent 31d59271
......@@ -1453,7 +1453,7 @@ bool SystemTools::PathCygwinToWin32(const char* path, char* win32_path)
bool SystemTools::Touch(const std::string& filename, bool create)
{
if (!SystemTools::PathExists(filename)) {
if (!SystemTools::FileExists(filename)) {
if (create) {
FILE* file = Fopen(filename, "a+b");
if (file) {
......
......@@ -422,6 +422,28 @@ static bool CheckFileOperations()
res = false;
}
#if !defined(_WIN32)
std::string const testBadSymlink(testNewDir + "/badSymlink.txt");
std::string const testBadSymlinkTgt(testNewDir + "/missing/symlinkTgt.txt");
if (!kwsys::SystemTools::CreateSymlink(testBadSymlinkTgt, testBadSymlink)) {
std::cerr << "Problem with CreateSymlink for: " << testBadSymlink << " -> "
<< testBadSymlinkTgt << std::endl;
res = false;
}
if (!kwsys::SystemTools::Touch(testBadSymlink, false)) {
std::cerr << "Problem with Touch (no create) for: " << testBadSymlink
<< std::endl;
res = false;
}
#endif
if (!kwsys::SystemTools::Touch(testNewDir, false)) {
std::cerr << "Problem with Touch (no create) for: " << testNewDir
<< std::endl;
res = false;
}
kwsys::SystemTools::Touch(testNewFile, true);
if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
std::cerr << "Problem with RemoveADirectory for: " << testNewDir
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment