Skip to content

Commit 2d0f107

Browse files
authored
Use file.exists instead of try-catch (#693)
See #692
1 parent 1ccacc9 commit 2d0f107

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/ini_to_core_reader.cpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ int INIToCoreReader::valueHandler(void *user, const char *section,
105105
Rcpp::Function normalizePath = base["normalizePath"];
106106
Rcpp::Function dirname = base["dirname"];
107107
Rcpp::Function filepath = base["file.path"];
108+
Rcpp::Function fileexists = base["file.exists"];
108109
#endif
109110

110111
static const string csvFilePrefix = "csv:";
@@ -144,20 +145,11 @@ int INIToCoreReader::valueHandler(void *user, const char *section,
144145
// If the csvFileName normalizes to a real path, use that.
145146
// Otherwise, assume that it is pointing to a file in the
146147
// same directory as the INI file.
147-
try {
148-
// Second argument is "winslash", which is only used
149-
// on Windows machines and is ignored for Unix-based
150-
// systems. "\\" (single backward slash) is the
151-
// default. Need it here to access the third argument
152-
// -- mustWork -- which throws the error to be caught
153-
// if the path doesn't exist
154-
csvFileName = Rcpp::as<string>(normalizePath(csvFileName, "\\", true));
155-
} catch (...) {
156-
// Get the full path of the INI file with
157-
// normalizePath. Then, get just the directory using dirname.
158-
Rcpp::String parentPath = dirname(normalizePath(reader->iniFilePath));
159-
csvFileName = Rcpp::as<string>(filepath(parentPath, csvFileName));
160-
}
148+
// csvFileName = Rcpp::as<string>(filepath(csvFileName));
149+
if(!Rcpp::as<bool>(fileexists(csvFileName))) {
150+
Rcpp::String parentPath = dirname(normalizePath(reader->iniFilePath));
151+
csvFileName = Rcpp::as<string>(filepath(parentPath, csvFileName));
152+
}
161153
#else
162154
// ANS:: Algorithm for standalone Hector. Same logic -- if
163155
// the given path (absolute or relative) points to a file

0 commit comments

Comments
 (0)