Skip to content

Conversation

@b33-stinger
Copy link

@b33-stinger b33-stinger commented Dec 31, 2025

devtools.go didn't check whether the path actually has offline.bnk before using it as the filePath

Summary by CodeRabbit

  • Bug Fixes
    • Improved offline cache detection for Snap and Flatpak installations on Linux, ensuring the application correctly locates cached data in the appropriate package manager directories.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

📝 Walkthrough

Walkthrough

Modified Linux path resolution in devtools.go to compute and prioritize offline.bnk cache files for Snap and Flatpak installations. The code now checks for these specific offline cache files and uses them when available, falling back to the default cache location otherwise. Darwin and Windows paths unchanged.

Changes

Cohort / File(s) Summary
Linux Path Resolution Logic
src/cmd/devtools.go
Added computed paths snapOfflineBNK and flatpakOfflineBNK for offline cache locations. Modified control flow to prioritize offline.bnk files from Snap and Flatpak caches over base directories, with fallback to default homePath/.cache/spotify/offline.bnk.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit hops through Linux trees, 🐰
Finding offline caches with ease,
Snap and Flatpak paths aligned,
Spotify's secrets no longer blind,
Smart priorities, the way's refined! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Better offline.bnk detection (linux)' directly and specifically describes the main change in the pull request: improving offline.bnk detection on Linux by adding proper path verification and fallback logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rxri
Copy link
Member

rxri commented Dec 31, 2025

Flatpak version stores offline.bnk in <flatpak home>/config/spotify/prefs. The else statement is for normal spotify installs

@rxri rxri closed this Dec 31, 2025
Copy link

@coderabbitai coderabbitai bot left a 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.Join is more idiomatic in Go and provides better consistency with the Windows and Darwin cases (which use filepath.Join at 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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad4b720 and fb38559.

📒 Files selected for processing (1)
  • src/cmd/devtools.go

Comment on lines 29 to +34
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"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@b33-stinger
Copy link
Author

Flatpak version stores offline.bnk in <flatpak home>/config/spotify/prefs. The else statement is for normal spotify installs

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 offline.bnk file and it would always tell be "couldn't find offline.bnk" (because it detected flatpak spotify and skipped my "normal" path). My pr just makes sure offline.bnk exists in the folder before using it.
Not something worth patching?

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 this pull request may close these issues.

2 participants