Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/cmd/devtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ func EnableDevTools() {
{
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"

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

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.

filePath = snapOfflineBNK
} else {
filePath = homePath + "/.cache/spotify/offline.bnk"
if _, err := os.Stat(flatpakOfflineBNK); err == nil {
homePath = flatpakHome
filePath = flatpakOfflineBNK
} else {
filePath = homePath + "/.cache/spotify/offline.bnk"
}
}

}
case "darwin":
filePath = os.Getenv("HOME") + "/Library/Application Support/Spotify/PersistentCache/offline.bnk"
Expand Down
Loading