-
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
Add check for absolute path of config file #1276
Conversation
src/utils/configfile.cc
Outdated
@@ -88,7 +88,9 @@ bool ConfigFile::Init(OptionsParser* options) { | |||
// loading the default configuration file. | |||
if (filename == "") return true; | |||
|
|||
filename = CommandLine::BinaryDirectory() + "/" + filename; | |||
if (filename.at(0) != '/') { |
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.
This fix will work on Unix-like operating systems, but seems to leave Windows (where absolute paths tend to start with C:\
, D:\
, etc) users in the cold.
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 have added a preprocessor directive to check for windows, then check for a colon in that path. I don't have a way to whether the windows section is robust though.
Thanks for pointing that out though! I forgot that this project is for windows too!
Now that we support C++17, I think https://stackoverflow.com/a/43278300 is more robust and prettier (probably there exist corner cases where the second character of an absolute path on Windows is not a colon). Hmm, there is even a function On a side note: the current code throws an exception which kills the engine on Windows for single character filenames. |
The compiler can't find the <filesystem>. I have no idea why not.
CI on Windows systems passes. Only Android on Appveyor and Linux on Circle CI fail, probably because of this (see https://en.cppreference.com/w/cpp/filesystem):
|
Just a quick hint for now, this should probably be handled in |
I initially pushed that commit because I had no idea why my compiler couldn't find Now that I can actually test my code, I am getting a segfault whenever I call the for example, just having the line
I'll have a go at porting it over (I said 'now' before, but I realise now that this isn't a copy-paste job to move it over) |
Seems |
Uh I was going to suggest https://en.cppreference.com/w/cpp/filesystem/path/is_absrel but see it's already being discussed. :) |
Note that for Windows, both Maybe regex-based approach would work? :) Something like And technically speaking |
How about making it similar to weights file autodiscover? Basically if the value is |
I have used the check for first character
I have retained this functionality I think, by not messing with how it works currently for the most part. I really appreciate all of your help everyone (not that this is necessarily done). Please keep the feedback coming - I am really enjoying my first open source experience :) |
IMO the main issue here is that the current functionality (in the release) is confusing: the config file can only reside in a path that is relative to the directory where the binary is located. This is a very weird convention. Normally paths are either absolute or relative to the current working dir. So I like @mooskagh's idea. |
Ahh I think I understand how that is different to what I have done/what happens at the moment. Do you want me to go full steam ahead on that @lealgo ? EDIT: Also, I have no idea how to show the linker where to find the windows API method which I used to determine if the path is relative. Directions would be very appreciated, as I have very little experience with building projects (university doesn't seem to think its so important lol...) |
Yeah (unless someone objects) I think having it only search in the directory of the binary if it's " That way we'll also be able to search multiple locations by default in future, which is useful for linux (i.e. |
The current solution comes forward to what @mooskagh suggested, allows users to specify an absolute path and treats relative paths (except the default config filename itself, but this can be overruled to use the file in the working dir by using Nit: there are still some stale unneeded |
Well spotted! cheers! |
src/utils/configfile.cc
Outdated
filename = CommandLine::BinaryDirectory() + "/" + filename; | ||
// Check to see if we are using the default config file or not. | ||
const bool using_default_config = | ||
filename == std::string(kDefaultConfigFile); |
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 think it's better to have a separate value for default behaviour, like "<default>
" or "<auto>
" (which still will read $LC0_DIRECTORY/lc0.config
), similarly to what we have for weights file (there we have "<autodiscover>
").
Otherwise when run like ./lc0 -c lc0.cfg
it will search in the current directory, while for ./lc0 -c lc0.config
it will search in the directory of the binary, which is a confusing inconsistency.
Also in future we'll try several locations by default (possibly with different file names, not only directories, e.g. /etc/lc0.cfg
vs ~/.lc0rc
), and it's more logical if the parameter doesn't have file name in it.
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 have made changes along these lines. Let me know if this is what you were thinking 🙂
src/utils/configfile.cc
Outdated
@@ -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>"; |
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:
const char* kDefaultConfigFile = "lc0.config";
const char* kDefaultConfigFileParam = "<default>";
(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!
#1071
Added absolute path capability for specifying config file.
This is my first time addressing an issue with a GitHub commit - if I have screwed up anything, please let me know! :)