Additions to domain/ and workspace/ chron-note packages

This commit is contained in:
2026-03-11 14:03:52 +08:00
parent 8edeb3ac99
commit 34d18e244e
16 changed files with 744 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
package workspace
import (
"fmt"
"io/fs"
"os"
"git.michelsen.id/phill/chron/chron-note/internal/domain"
)
func (ws *Workspace) ListObjectIDs() ([]domain.ObjectID, error) {
entries, err := os.ReadDir(ws.Dir)
if err != nil {
return nil, fmt.Errorf("readdir workspace dir: %w", err)
}
out := make([]domain.ObjectID, 0, len(entries))
for _, e := range entries {
if e.IsDir() {
continue
}
info, err := e.Info()
if err != nil {
return nil, fmt.Errorf("stat workspace entry: %w", err)
}
if !info.Mode().IsRegular() {
continue
}
id, err := domain.ParseObjectID(e.Name())
if err != nil {
continue
}
out = append(out, id)
}
return out, nil
}
func (ws *Workspace) Stat(id domain.ObjectID) (fs.FileInfo, error) {
fi, err := os.Stat(ws.ObjectPath(id))
if err != nil {
return nil, fmt.Errorf("stat object %s: %w", id.String(), err)
}
return fi, nil
}