-
Notifications
You must be signed in to change notification settings - Fork 59
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
Fix Segmentation fault if HOME not set #162
Conversation
If the user-specified cache directory had other content the user cared about, then clearing the cache would wipe that directory along with the non-httpdirfs content. Perhaps the help should be updated with this comment? |
Yeh, your previous pull request successfully address the stated GitHub issue, so I merged it. If you cherry-pick this on top of the current master, update the pull request saying that it fixes #154, I will merge it if it is up to standard like the previous one. |
602e449
to
9fb6226
Compare
You need to rebase your changes on top the head of the master branch. There are merge conflicts. The quickest way to resolve it is to rebase. I was happy with your previous commit, that's why I merged it. :) |
Commenting as @EyitopeIO Good to know. Thanks. I'm testing with |
fc97fc7
to
c2a2807
Compare
I think I don't have permissions to edit the PR title because I don't see the edit button. |
src/cache.c
Outdated
home = path_append(user_home, xdg_default); | ||
} | ||
} else { | ||
home = path_append(xdg_home, xdg_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.
Is this what we really want to do? When xdg_home
== "XDG_CACHE_HOME"
In general you need to take more care about your variable names, I think. |
0e5c191
to
452757a
Compare
src/main.c
Outdated
lprintf(warning, "$HOME is unset\n"); | ||
char *cur_dir = realpath("./", NULL); | ||
if (!cur_dir) { | ||
lprintf(fatal, "Could not get config directory\n"); |
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 should not be fatal, if the software cannot get the config directory, it should keep running. This should just be a warning.
src/cache.c
Outdated
/* | ||
* "XDG_CACHE_HOME/HOME/.cache" > "HOME/.cache" > "./.cache" | ||
*/ | ||
char *xdg = getenv("XDG_CACHE_HOME"); |
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.
rename xdg
to xdg_cache_home
.
src/main.c
Outdated
{ | ||
const char *default_config_subdir = "/.config"; | ||
char *config_dir; | ||
char *xdg = getenv("XDG_CONFIG_HOME"); |
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.
rename this xdg
to xdg_config_home
.
src/cache.c
Outdated
/* | ||
* "XDG_CACHE_HOME/HOME/.cache" > "HOME/.cache" > "./.cache" | ||
*/ |
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 am not sure if the comment reflects what's actually happening. The code is clear enough describing what's happening. Perhaps delete this?
src/cache.c
Outdated
* "XDG_CACHE_HOME/HOME/.cache" > "HOME/.cache" > "./.cache" | ||
*/ | ||
char *xdg = getenv("XDG_CACHE_HOME"); | ||
if (!xdg) { |
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 would invert the this condition to make the whole thing clearer.
src/main.c
Outdated
const char *default_config_subdir = "/.config"; | ||
char *config_dir; | ||
char *xdg = getenv("XDG_CONFIG_HOME"); | ||
if (!xdg) { |
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 would invert the this condition to make the whole thing clearer.
src/cache.c
Outdated
char *xdg = getenv("XDG_CACHE_HOME"); | ||
if (!xdg) { | ||
char *user_home = getenv("HOME"); | ||
if (!user_home) { |
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 would invert this condition too.
src/main.c
Outdated
char *xdg = getenv("XDG_CONFIG_HOME"); | ||
if (!xdg) { | ||
char *user_home = getenv("HOME"); | ||
if (!user_home) { |
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 would invert this condition.
Please address all the code quality issues introduced by your change flagged up by the static analysers. Also, in general, when you have a if statement, you should condition them in such a way that the most common condition occurs at the first branch, so the code is easier to read. This is what I want in this repository for new contributions. For example, I prefer:
I don't like:
Anyways, this pull request is heading towards a good direction. I like it so far. |
Comments on static analyser
|
4b846e6
to
c45ef51
Compare
Quality Gate passedIssues Measures |
Fixes #154