Skip to content

Commit fce56eb

Browse files
committed
Remove index checking, use listing
1 parent ebe94d2 commit fce56eb

File tree

1 file changed

+4
-43
lines changed

1 file changed

+4
-43
lines changed

toolprovider/mise/mise.go

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package mise
22

33
import (
4-
"encoding/json"
54
"errors"
65
"fmt"
76
"os"
@@ -127,6 +126,7 @@ func (m *MiseToolProvider) InstallTool(tool provider.ToolRequest) (provider.Tool
127126
}
128127

129128
if !useNix {
129+
// Nix already checks version existence previously
130130
versionExists, err := m.versionExists(tool.ToolName, tool.UnparsedVersion)
131131
if err != nil {
132132
return provider.ToolInstallResult{}, fmt.Errorf("check if version exists: %w", err)
@@ -224,7 +224,9 @@ func (m *MiseToolProvider) shouldUseNixPkgs(tool provider.ToolRequest) bool {
224224
return false
225225
}
226226

227-
available, err := availableInNixIndex(tool.ToolName, tool.UnparsedVersion)
227+
nameWithBackend := provider.ToolID(fmt.Sprintf("nixpkgs:%s", tool.ToolName))
228+
229+
available, err := m.versionExists(nameWithBackend, tool.UnparsedVersion)
228230
if err != nil || !available {
229231
log.Warnf("Failed to check nixpkgs index for %s@%s: %v. Falling back to legacy installation.", tool.ToolName, tool.UnparsedVersion, err)
230232
return false
@@ -306,47 +308,6 @@ func (m *MiseToolProvider) getNixpkgsPlugin() error {
306308
return nil
307309
}
308310

309-
type nixpkgsIndex struct {
310-
Pkgs map[string]map[string]interface{} `json:"pkgs"`
311-
}
312-
313-
func availableInNixIndex(toolName provider.ToolID, version string) (bool, error) {
314-
// Find the index file
315-
indexPath, err := findIndexPath()
316-
if err != nil {
317-
return false, err
318-
}
319-
320-
// Read the index file
321-
data, err := os.ReadFile(indexPath)
322-
if err != nil {
323-
return false, fmt.Errorf("read index file: %w", err)
324-
}
325-
326-
// Parse JSON
327-
var index nixpkgsIndex
328-
if err := json.Unmarshal(data, &index); err != nil {
329-
return false, fmt.Errorf("parse index JSON: %w", err)
330-
}
331-
332-
// Check if tool exists
333-
toolVersions, toolExists := index.Pkgs[string(toolName)]
334-
if !toolExists {
335-
log.Debugf("[TOOLPROVIDER] Tool %s not found in nixpkgs index", toolName)
336-
return false, nil
337-
}
338-
339-
// Check if version exists
340-
_, versionExists := toolVersions[version]
341-
if !versionExists {
342-
log.Debugf("[TOOLPROVIDER] Version %s not found for tool %s in nixpkgs index", version, toolName)
343-
return false, nil
344-
}
345-
346-
log.Debugf("[TOOLPROVIDER] Tool %s version %s found in nixpkgs index", toolName, version)
347-
return true, nil
348-
}
349-
350311
// cloneGitRepo clones a git repository to the specified path with minimal history.
351312
func cloneGitRepo(repoURL, destPath string) error {
352313
cmd := exec.Command("git", "clone", "--depth", "1", "--no-tags", repoURL, destPath)

0 commit comments

Comments
 (0)