-
-
Notifications
You must be signed in to change notification settings - Fork 827
Better offline.bnk detection (linux) #3673
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
Conversation
📝 WalkthroughWalkthroughModified Linux path resolution in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Flatpak version stores |
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/cmd/devtools.go (1)
30-33: Consider using filepath.Join for path construction.While string concatenation works on Linux, using
filepath.Joinis more idiomatic in Go and provides better consistency with the Windows and Darwin cases (which usefilepath.Joinat line 25).🔎 Example refactor using filepath.Join
- snapSpotifyHome := homePath + "/snap/spotify/common" - snapOfflineBNK := snapSpotifyHome + "/cache/spotify/offline.bnk" - flatpakHome := homePath + "/.var/app/com.spotify.Client" - flatpakOfflineBNK := flatpakHome + "/cache/spotify/offline.bnk" + snapSpotifyHome := filepath.Join(homePath, "snap", "spotify", "common") + snapOfflineBNK := filepath.Join(snapSpotifyHome, "cache", "spotify", "offline.bnk") + flatpakHome := filepath.Join(homePath, ".var", "app", "com.spotify.Client") + flatpakOfflineBNK := filepath.Join(flatpakHome, "cache", "spotify", "offline.bnk") if _, err := os.Stat(snapOfflineBNK); err == nil { filePath = snapOfflineBNK } else { if _, err := os.Stat(flatpakOfflineBNK); err == nil { filePath = flatpakOfflineBNK } else { - filePath = homePath + "/.cache/spotify/offline.bnk" + filePath = filepath.Join(homePath, ".cache", "spotify", "offline.bnk") } }Also applies to: 43-43
| homePath := os.Getenv("HOME") | ||
| snapSpotifyHome := homePath + "/snap/spotify/common" | ||
| if _, err := os.Stat(snapSpotifyHome); err == nil { | ||
| homePath = snapSpotifyHome | ||
| } | ||
|
|
||
| snapOfflineBNK := snapSpotifyHome + "/cache/spotify/offline.bnk" | ||
| flatpakHome := homePath + "/.var/app/com.spotify.Client" | ||
| if _, err := os.Stat(flatpakHome); err == nil { | ||
| homePath = flatpakHome | ||
| filePath = homePath + "/cache/spotify/offline.bnk" | ||
| flatpakOfflineBNK := flatpakHome + "/cache/spotify/offline.bnk" | ||
|
|
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.
Validate HOME environment variable.
If HOME is unset or empty, all constructed paths will be incorrect (e.g., starting with "/snap/..." instead of "/home/user/snap/..."). While rare in typical Linux environments, this could cause the function to fail silently or operate on unexpected paths.
🔎 Proposed fix to validate HOME
{
homePath := os.Getenv("HOME")
+ if homePath == "" {
+ utils.PrintError("HOME environment variable is not set")
+ os.Exit(1)
+ }
snapSpotifyHome := homePath + "/snap/spotify/common"
snapOfflineBNK := snapSpotifyHome + "/cache/spotify/offline.bnk"
flatpakHome := homePath + "/.var/app/com.spotify.Client"
flatpakOfflineBNK := flatpakHome + "/cache/spotify/offline.bnk"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| homePath := os.Getenv("HOME") | |
| snapSpotifyHome := homePath + "/snap/spotify/common" | |
| if _, err := os.Stat(snapSpotifyHome); err == nil { | |
| homePath = snapSpotifyHome | |
| } | |
| snapOfflineBNK := snapSpotifyHome + "/cache/spotify/offline.bnk" | |
| flatpakHome := homePath + "/.var/app/com.spotify.Client" | |
| if _, err := os.Stat(flatpakHome); err == nil { | |
| homePath = flatpakHome | |
| filePath = homePath + "/cache/spotify/offline.bnk" | |
| flatpakOfflineBNK := flatpakHome + "/cache/spotify/offline.bnk" | |
| homePath := os.Getenv("HOME") | |
| if homePath == "" { | |
| utils.PrintError("HOME environment variable is not set") | |
| os.Exit(1) | |
| } | |
| snapSpotifyHome := homePath + "/snap/spotify/common" | |
| snapOfflineBNK := snapSpotifyHome + "/cache/spotify/offline.bnk" | |
| flatpakHome := homePath + "/.var/app/com.spotify.Client" | |
| flatpakOfflineBNK := flatpakHome + "/cache/spotify/offline.bnk" |
🤖 Prompt for AI Agents
In src/cmd/devtools.go around lines 29 to 34, the code reads HOME and
immediately constructs paths which will be invalid if HOME is unset or empty;
validate HOME before using it and handle failure by either calling
os.UserHomeDir() as a fallback or returning an error so you don't build
incorrect paths. Update the function to check if homePath == "" (or err from
os.LookupEnv) and then attempt os.UserHomeDir(); if that also fails, return a
clear error (or log and exit) instead of proceeding to build snap/flatpak paths
with an empty prefix.
| flatpakOfflineBNK := flatpakHome + "/cache/spotify/offline.bnk" | ||
|
|
||
| if _, err := os.Stat(snapOfflineBNK); err == nil { | ||
| homePath = snapSpotifyHome |
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.
Remove unused homePath assignments.
The homePath variable is reassigned at lines 36 and 40, but it's never used after the switch statement ends at line 49. These assignments have no effect and can be safely removed.
🔎 Proposed fix
if _, err := os.Stat(snapOfflineBNK); err == nil {
- homePath = snapSpotifyHome
filePath = snapOfflineBNK
} else {
if _, err := os.Stat(flatpakOfflineBNK); err == nil {
- homePath = flatpakHome
filePath = flatpakOfflineBNK
} else {
filePath = homePath + "/.cache/spotify/offline.bnk"
}
}Also applies to: 40-40
🤖 Prompt for AI Agents
In src/cmd/devtools.go around lines 36 and 40, the assignments to homePath
(homePath = snapSpotifyHome and the other reassignment) inside the switch are
unused after the switch ends; remove these redundant homePath assignments (and
if homePath is otherwise unused in the function, remove its declaration) so the
switch only sets values actually consumed or has no-op branches removed.
i had a problem that i unknowingly had a spotify folder from flatpak but i didn't use flatpak spotify, so it didn't have the |
devtools.godidn't check whether the path actually hasoffline.bnkbefore using it as thefilePathSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.