-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file not found output message #8324
Changes from 15 commits
c4f656d
80e4d8f
2ab0ac8
22126fc
578d433
8f6e5ea
8a3db61
75cd34d
e91271b
2f839eb
31a59c4
631eb86
11911ee
62d43df
f04d3a3
7d82651
b0ed48c
296a9b9
5438bb1
4a93d7e
f1bcbbd
fbdcded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ | |
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
|
||
//C++ Headers | ||
#include <utility> | ||
|
||
// ObjexxFCL Headers | ||
#include <ObjexxFCL/environment.hh> | ||
#include <ObjexxFCL/gio.hh> | ||
|
@@ -202,7 +205,8 @@ namespace DataSystemVariables { | |
void CheckForActualFileName(IOFiles &ioFiles, | ||
std::string const &originalInputFileName, // name as input for object | ||
bool &FileFound, // Set to true if file found and is in CheckedFileName | ||
std::string &CheckedFileName // Blank if not found. | ||
std::string &CheckedFileName, // Blank if not found. | ||
const std::string contextString // | ||
) | ||
{ | ||
|
||
|
@@ -217,28 +221,13 @@ namespace DataSystemVariables { | |
// be accurate. This searches a few folders (CurrentWorkingFolder, Program folder) to see | ||
// if the file can be found. (It may have been input with full path so that is checked first.) | ||
|
||
// METHODOLOGY EMPLOYED: | ||
// na | ||
|
||
// REFERENCES: | ||
// na | ||
|
||
// USE STATEMENTS: | ||
// na | ||
|
||
// Locals | ||
// SUBROUTINE ARGUMENT DEFINITIONS: | ||
|
||
// SUBROUTINE PARAMETER DEFINITIONS: | ||
static std::string const blank; | ||
static ObjexxFCL::gio::Fmt fmtA("(A)"); | ||
|
||
// INTERFACE BLOCK SPECIFICATIONS: | ||
// na | ||
|
||
// DERIVED TYPE DEFINITIONS: | ||
// na | ||
|
||
// SUBROUTINE LOCAL VARIABLE DECLARATIONS: | ||
std::string InputFileName; // save for changing out path characters | ||
std::string::size_type pos; | ||
|
@@ -255,81 +244,44 @@ namespace DataSystemVariables { | |
firstTime = false; | ||
} | ||
|
||
|
||
FileFound = false; | ||
CheckedFileName = blank; | ||
InputFileName = originalInputFileName; | ||
makeNativePath(InputFileName); | ||
|
||
if (FileSystem::fileExists(InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (user input)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (user input)", getAbsolutePath(InputFileName)); | ||
} | ||
|
||
// Look relative to input file path | ||
if (FileSystem::fileExists(DataStringGlobals::inputDirPathName + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = DataStringGlobals::inputDirPathName + InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (input file)", getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)); | ||
} | ||
|
||
// Look relative to input path | ||
if (FileSystem::fileExists(envinputpath1 + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = envinputpath1 + InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (epin)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (epin)", getAbsolutePath(envinputpath1 + InputFileName)); | ||
} | ||
|
||
// Look relative to input path | ||
if (FileSystem::fileExists(envinputpath2 + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = envinputpath2 + InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (input_path)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (input_path)", getAbsolutePath(envinputpath2 + InputFileName)); | ||
} | ||
|
||
// Look relative to program path | ||
if (FileSystem::fileExists(envprogrampath + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = envprogrampath + InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (program_path)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (program_path)", getAbsolutePath(envprogrampath + InputFileName)); | ||
} | ||
|
||
if (!TestAllPaths) return; | ||
|
||
// Look relative to current working folder | ||
if (FileSystem::fileExists(CurrentWorkingFolder + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = CurrentWorkingFolder + InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (CWF)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (CWF)", getAbsolutePath(CurrentWorkingFolder + InputFileName)); | ||
std::vector<std::pair<std::string, std::string>> pathsChecked; | ||
|
||
const std::vector<std::pair<std::string, std::string>> pathsToCheck = { | ||
{InputFileName, "InputFileName"}, | ||
{DataStringGlobals::inputDirPathName + InputFileName, "inputDirPathName"}, | ||
{envinputpath1 + InputFileName, "envinputpath1"}, | ||
{envinputpath2 + InputFileName, "envinputpath2"}, | ||
{envprogrampath + InputFileName, "envprogrampath"}, | ||
{CurrentWorkingFolder + InputFileName, "CurrentWorkingFolder"}, | ||
{ProgramPath + InputFileName, "ProgramPath"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ajscimone Here are more informative descriptions for each of the strings that describe where files are searched:
We should maybe add @Myoldmopar @mjwitte thoughts on any of this? Separate question: Does/should this interact with the way python plug-in paths are searched? |
||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is quite a small list, so it's not a big deal, but an array would've been acceptable here since I think this vector is staying fixed length. |
||
|
||
std::size_t numPathsToNotTest = (TestAllPaths) ? pathsToCheck.size()-2 : pathsToCheck.size(); | ||
|
||
for(std::size_t i = 0; i < numPathsToNotTest; i++) { | ||
if (FileSystem::fileExists(pathsToCheck[i].first)) { | ||
FileFound = true; | ||
CheckedFileName = pathsToCheck[i].first; | ||
print(ioFiles.audit, "{}={}\n", "found (" + pathsToCheck[i].second +")", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
std::pair <std::string,std::string> currentPath(getAbsolutePath(pathsToCheck[i].first), pathsToCheck[i].second); | ||
if (std::find(pathsChecked.begin(), pathsChecked.end(), currentPath) == pathsChecked.end()){ | ||
pathsChecked.push_back(currentPath); | ||
} | ||
print(ioFiles.audit, "{}={}\n", "not found (" + pathsToCheck[i].second +")\"", getAbsolutePath(pathsToCheck[i].first)); | ||
} | ||
} | ||
|
||
// Look relative to program path | ||
if (FileSystem::fileExists(ProgramPath + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = ProgramPath + InputFileName; | ||
print(ioFiles.audit, "{}={}\n", "found (program path - ini)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(ioFiles.audit, "{}={}\n", "not found (program path - ini)", getAbsolutePath(ProgramPath + InputFileName)); | ||
if (!FileFound) { | ||
ShowSevereError(contextString+ "\"" + originalInputFileName + "\" not found. Paths searched:"); | ||
for(auto path: pathsChecked){ | ||
ShowContinueError(" (" + path.second +")\"" + path.first +"\""); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
true
means error. OK. A little confusing maybe but not a big deal. If other commits are needed here for anything, I'd suggest considering a clearer convention likebool loadSuccess()
where true is clearly success. Anyway, not a big deal if it's working.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was kind of thinking of it as an error code return where
0
/false
means success.