Skip to content
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

Bug: '@include' path isn't relative to the lib-loaded config file. #103

Open
lowlevl opened this issue Feb 6, 2018 · 4 comments
Open

Bug: '@include' path isn't relative to the lib-loaded config file. #103

lowlevl opened this issue Feb 6, 2018 · 4 comments

Comments

@lowlevl
Copy link
Contributor

lowlevl commented Feb 6, 2018

Hi @hyperrealm, I'm using your lib in my project, and I noticed a bug, @include isn't relative to the current file, but to the execution directory.

Here is my working environnement:

parentdir/
|- project/
|   |- sysconf/
|       |- main.cf
|       |- otherconf.cf 
|- project-build/
    |- project-executable

My main.cc is loading the main.cf like following because I execute the binary from the build directory:

  libconfig::Config config;
  try {
    config.readFile("../project/sysconf/main.cf");
  } catch (libconfig::ParseException e) {
    std::cout << std::string(e.getError()) << " on line: " << std::to_string(e.getLine())) << std::endl;
  }

From here there is no bug, now look to my main.cf:

@include "otherconf.cf"

Which produce: cannot open include file on line: 1.

But when I use this main.cf:

@include "../project/sysconf/otherconf.cf"

It works perfectly well.

Edit: I think I need to set and include directory ? Wouldn't it be better to treat @include path as relative ?

@lowlevl
Copy link
Contributor Author

lowlevl commented Feb 6, 2018

Sorry, I didn't really read the documentation, but relative path to the current file seemed so intuitive that, I'll transform this issue in an improvement request.

Edit: Of course I can help !

@hyperrealm
Copy link
Owner

It may be tricky to get the location of the file; may require platform-specific code for Unix, Windows, etc.. If you can write a patch to implement this, I'll be happy to look it over.

@lowlevl
Copy link
Contributor Author

lowlevl commented Oct 10, 2018

I don't think that would be too tricky :)
Since the readFile() function passes a string with the loaded file path, we could just use on insert:

/* Pseudo-Code */
if(directive == "include")
{
    doInclude(dirname(filePath) + includePath);
}

Don't you think ? @hyperrealm

@lowlevl
Copy link
Contributor Author

lowlevl commented Oct 10, 2018

So somehow it would do:

/* Pseudo-Code */
doInclude("../project/sysconf/" + "otherconf.cf");

to recreate the @include "../project/sysconf/otherconf.cf".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants