Skip to content
Snippets Groups Projects
Commit 6d83c113 authored by Jean-Christophe Fillion-Robin's avatar Jean-Christophe Fillion-Robin Committed by Brad King
Browse files

SystemTools: Fix DetectFileType failure on directory

Some operating systems allow directories to be opened and read like
files while others do not.  Simply check for a directory type first.

Change-Id: Ic970f662d5aa887ace4a8f166ede7e0d1531d0d6
parent e5c23738
No related branches found
No related tags found
No related merge requests found
......@@ -4230,6 +4230,11 @@ SystemTools::DetectFileType(const char *filename,
return SystemTools::FileTypeUnknown;
}
if (SystemTools::FileIsDirectory(filename))
{
return SystemTools::FileTypeUnknown;
}
FILE *fp = Fopen(filename, "rb");
if (!fp)
{
......
......@@ -100,6 +100,8 @@ static bool CheckFileOperations()
bool res = true;
const kwsys_stl::string testNonExistingFile(TEST_SYSTEMTOOLS_SOURCE_DIR
"/testSystemToolsNonExistingFile");
const kwsys_stl::string testDotFile(TEST_SYSTEMTOOLS_SOURCE_DIR
"/.");
const kwsys_stl::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR
"/testSystemTools.bin");
const kwsys_stl::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR
......@@ -117,6 +119,15 @@ static bool CheckFileOperations()
res = false;
}
if (kwsys::SystemTools::DetectFileType(testDotFile.c_str()) !=
kwsys::SystemTools::FileTypeUnknown)
{
kwsys_ios::cerr
<< "Problem with DetectFileType - failed to detect type of: "
<< testDotFile << kwsys_ios::endl;
res = false;
}
if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) !=
kwsys::SystemTools::FileTypeBinary)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment