-
Notifications
You must be signed in to change notification settings - Fork 535
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
Add check for absolute path of config file #1276
Changes from 14 commits
5109e94
6743db9
104408e
0f01c91
bbc9a02
b0360c7
b14a0c0
062fbab
0c54367
95b081b
65c23b2
ea7e4b8
d9adf7e
a603ec1
8fc4bba
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 |
---|---|---|
|
@@ -42,7 +42,7 @@ const OptionId kConfigFileId{ | |
"Path to a configuration file. The format of the file is one command line " | ||
"parameter per line, e.g.:\n--weights=/path/to/weights", | ||
'c'}; | ||
const char* kDefaultConfigFile = "lc0.config"; | ||
const char* kDefaultConfigFile = "<default>"; | ||
} // namespace | ||
|
||
std::vector<std::string> ConfigFile::arguments_; | ||
|
@@ -81,28 +81,33 @@ std::string ConfigFile::ProcessConfigFlag( | |
bool ConfigFile::Init(OptionsParser* options) { | ||
arguments_.clear(); | ||
|
||
// Get the relative path from the config file parameter. | ||
// Get the path from the config file parameter. | ||
std::string filename = ProcessConfigFlag(CommandLine::Arguments()); | ||
|
||
// If filename is an empty string then return true. This is to override | ||
// If filename is an empty string then return true. This is to override | ||
// loading the default configuration file. | ||
if (filename == "") return true; | ||
|
||
filename = CommandLine::BinaryDirectory() + "/" + filename; | ||
|
||
// Parses the file into the arguments_ vector. | ||
if (!ParseFile(filename, options)) return false; | ||
|
||
return true; | ||
} | ||
|
||
bool ConfigFile::ParseFile(const std::string& filename, | ||
bool ConfigFile::ParseFile(std::string& filename, | ||
OptionsParser* options) { | ||
std::ifstream input(filename); | ||
|
||
// Check to see if we are using the default config file or not. | ||
OptionsDict dict = options->GetOptionsDict(); | ||
const bool using_default_config = dict.IsDefault<std::string>(kConfigFileId); | ||
const bool using_default_config = | ||
filename == std::string(kDefaultConfigFile); | ||
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. I think it's better to have a separate value for default behaviour, like " Otherwise when run like Also in future we'll try several locations by default (possibly with different file names, not only directories, e.g. 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. I have made changes along these lines. Let me know if this is what you were thinking 🙂 |
||
|
||
// If no logfile was set on the command line, then the default is | ||
// to check in the binary directory. | ||
if (using_default_config) { | ||
filename = CommandLine::BinaryDirectory() + "/lc0.config"; | ||
} | ||
|
||
std::ifstream input(filename); | ||
|
||
if (!input.is_open()) { | ||
// It is okay if we cannot open the default file since it is normal | ||
|
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.
Sorry for nitpicking, but I suggest moving both constants here:
(or if it's one, better it be the filename and not the option value)
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.
Not a problem. Do these changes match what you were thinking?
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.
Looks good!