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

$HOME/.pioneer is randomly created on Linux #5942

Closed
WickedSmoke opened this issue Oct 30, 2024 · 6 comments · Fixed by #5944
Closed

$HOME/.pioneer is randomly created on Linux #5942

WickedSmoke opened this issue Oct 30, 2024 · 6 comments · Fixed by #5944

Comments

@WickedSmoke
Copy link
Contributor

Occasionally the $HOME/.pioneer directory is created on Linux as the program thinks that directory already exists. The following patch should fix this.

diff --git a/src/posix/FileSystemPosix.cpp b/src/posix/FileSystemPosix.cpp
index b2a2ff8ec..fb36147b6 100644
--- a/src/posix/FileSystemPosix.cpp
+++ b/src/posix/FileSystemPosix.cpp
@@ -61,8 +61,8 @@ namespace FileSystem {
                path += "Library/Application Support/Pioneer";
 #else
                struct stat info;
-               stat((path + ".pioneer").c_str(), &info);
-               if (S_ISDIR(info.st_mode)) {
+               int err = stat((path + ".pioneer").c_str(), &info);
+               if (err == 0 && S_ISDIR(info.st_mode)) {
                        // Check for legacy pioneer directory.
                        path += ".pioneer";
                } else {
@WickedSmoke
Copy link
Contributor Author

Also, is there any guarantee that the temporary string object in (path + ".pioneer").c_str() exists during the stat() call?

@sturnclaw
Copy link
Member

Also, is there any guarantee that the temporary string object in (path + ".pioneer").c_str() exists during the stat() call?

There is a strong guarantee provided by the rules of the C++ language on lifetime. Temporary objects are guaranteed to last as least as long as their enclosing function call scope.

Additionally (continuing from IRC) the stat() function call has no requirement that the pathname parameter exist longer than the duration of the function call.

The following patch should fix this.

Thanks! Please feel free to submit that as a Pull Request and we can test it and merge it if it solves the problem.

@WickedSmoke
Copy link
Contributor Author

I seem to recall problems in the past (with QString -> const char*) where the object goes away before the call because the object is not what gets passed to the function.

Can a separate pull request be skipped for such a trivial fix?

@impaktor
Copy link
Member

Can a separate pull request be skipped for such a trivial fix?

There's three options as I see it:

  1. you PR it
  2. we copy the patch and apply on the source
  3. we PR it. (actually, if I did 2, I would open it as a PR, rather than push directly to master.

If it's the case you need help with github, we can PR it for you, but I assume you know how to do it, based on your code skill.

@WickedSmoke
Copy link
Contributor Author

I'm not going to clone the project on Github at this time, so please use the patch as you will.

@impaktor
Copy link
Member

impaktor commented Nov 1, 2024

I've opened a PR ☝️ for this patch.

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

Successfully merging a pull request may close this issue.

3 participants