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,52 @@
package workspace
import (
"context"
"fmt"
"os"
"git.michelsen.id/phill/chron/chron-note/internal/domain"
)
type SnapshotObject struct {
ID domain.ObjectID
Size int64
ModNS int64
}
func (ws *Workspace) Snapshot(ctx context.Context) ([]SnapshotObject, error) {
entries, err := os.ReadDir(ws.Dir)
if err != nil {
return nil, fmt.Errorf("readdir workspace dir: %w", err)
}
out := make([]SnapshotObject, 0, len(entries))
for _, e := range entries {
if ctx.Err() != nil {
return nil, ctx.Err()
}
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, SnapshotObject{
ID: id,
Size: info.Size(),
ModNS: info.ModTime().UnixNano(),
})
}
return out, nil
}