-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
refine handling of XDG directory resolution #14502
Conversation
My main question is around what we should do in this scenario. Using rstudio/src/cpp/core/system/Xdg.cpp Lines 206 to 219 in 7ecae3c
Which path should we use in this scenario -- |
aa65673
to
c6fee1c
Compare
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.
LGTM! We chatted elsewhere about theoretical performance concerns of this API now doing filesystem operations, and also that we can wait and merge this into the next release (not Chocolate Cosmos).
src/cpp/core/system/Xdg.cpp
Outdated
} | ||
|
||
// Free memory if allocated | ||
if (path != nullptr) |
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 if
isn't strictly necessary; CoTaskMemFree
can be safely called on a nullptr
.
Moving to draft to avoid unintentional merge; we might prefer taking this PR in the next release rather than Chocolate Cosmos? |
One other idea that arose while chatting with @gtritchie: should we be caching the computed values for XDG folder locations? It seems unlikely that we'd want to allow the user configuration directory to change during the lifetime of a process / session, but theoretically that could happen if the user were to set (for example) |
This existing code already has logic for choosing a folder based on presence of the rstudio/src/cpp/core/system/Xdg.cpp Lines 305 to 337 in e33a035
|
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.
LGTM! This is a great cleanup. So as I understand it, we still are choosing the first config directory that's found. If a specific config file doesn't exist in that dir, the latter config dirs won't be checked. That's how it's worked in the past but if we change that, it could theoretically break things in weird ways for individual customers because of the chaos that exists in the world :)
I do think caching would be fine for this api. It's an easy win to shave a fraction of a second off startup time.
If none of the dirs exist, choosing the "first one specified" makes sense to me. Maybe you want to create it in that scenario if you are using this from an admin UI tool, but it also seems like that tool should have already done that before this api was called.
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.
LGTM! Would adding some unit tests make sense for this?
Good idea; let me cook something up. |
// Even if one of the XDG directories exist, we ignore it since it doesn't contain | ||
// the logging.conf file we're looking for. | ||
boost::filesystem::create_directories(xdgConfigB); | ||
CHECK(systemConfigFile("logging.conf") == FilePath("/etc/rstudio/logging.conf")); |
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 this is the behavior we want, but it would be worth confirming.
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 that's right for this case because the main XDG directory does exist, but the rstudio
directory inside of it does not exist. So we ignore that XDG entry for rstudio config files. This is how it used to work so I think is right here.
// does not contain the system config file we're searching for, so it's skipped | ||
FilePath rstudioXdgConfigB = FilePath(xdgConfigB).completePath("rstudio"); | ||
rstudioXdgConfigB.ensureDirectory(); | ||
CHECK(systemConfigFile("logging.conf") == FilePath("/etc/rstudio/logging.conf")); |
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.
Same here?
I tried to remove a bit of duplicated code, and also added a number of test cases. (I also enabled stderr logging for tests while I was in that code). Can you look through the test cases and see if the asserted behavior is what we expect? In particular, I want to make sure I have the semantics around resolving a file within an XDG directory location correct. For example, suppose we're resolving
As a side note, https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html has:
which implies we're actually deviating from the standard a bit in using |
Seems reasonable to me; @jeffvroom might want to take another peek to confirm. |
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.
LGTM
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.
LGTM!
Intent
Addresses https://github.com/rstudio/rstudio-pro/issues/5658.
Approach
Automated Tests
TODO
QA Notes
Test via notes in https://github.com/rstudio/rstudio-pro/issues/5658.
Documentation
N/A
Checklist
NEWS.md