fix: return friendly paths for lazily mounted items

Fetch the uniquely identified item when mount metadata has not yet been
populated, so get-path does not fall back to the ID-based location.

💘 Generated with Crush

Assisted-by: Crush:openai/gpt-5.6-terra
This commit is contained in:
Jan Bader committed 2026-10-07 10:41:11 +02:00
1 parent 6041cc0a33
commit d15b7d082e
2 files changed
+41

No files matched your search

+22
View File
@@ -160,6 +160,18 @@ func runGetPathCommand(args []string, cfg config, password string) error {
fmt.Println(path)
return nil
}
client := NewDocspellClient(cfg.DocspellURL, defaultDocspellAuthHeader)
if err := client.Login(context.Background(), cfg.User, password); err != nil {
return fmt.Errorf("login: %w", err)
}
items, err := client.SearchItems(context.Background(), "id:"+id, 1)
if err != nil {
return fmt.Errorf("search item %s: %w", id, err)
}
if path := friendlyLocalPathForSearchItems(mountPoint, id, items); path != "" {
fmt.Println(path)
return nil
}
matches, err := filepath.Glob(filepath.Join(mountPoint, "by-id", idShard(id), id+".*"))
if err != nil {
return err
@@ -183,6 +195,16 @@ func friendlyLocalPathForItemID(mountPoint, id string) (string, error) {
return filepath.Join(mountPoint, filepath.FromSlash(item.FriendlyPath)), nil
}
func friendlyLocalPathForSearchItems(mountPoint, id string, items []SearchItem) string {
_, metadata := buildItemTree(items)
for itemID, item := range metadata.Items {
if strings.EqualFold(itemID, id) && item.FriendlyPath != "" {
return filepath.Join(mountPoint, filepath.FromSlash(item.FriendlyPath))
}
}
return ""
}
func readMountMetadata(mountPoint string) (mountMetadata, error) {
var metadata mountMetadata
data, err := os.ReadFile(filepath.Join(mountPoint, mountMetadataFileName))