Changeset 0.21.2 (#88)

This commit is contained in:
2026-03-01 17:45:50 +00:00
parent 09c7281552
commit c5159538ce
18 changed files with 1105 additions and 32 deletions

View File

@@ -46,6 +46,7 @@ const (
type FS struct {
basePath string // e.g. /data/storage/workspaces
store store.WorkspaceStore
indexer *Indexer // optional — set via SetIndexer for v0.21.2 indexing
}
// NewFS creates a workspace filesystem manager.
@@ -53,6 +54,12 @@ func NewFS(basePath string, ws store.WorkspaceStore) *FS {
return &FS{basePath: basePath, store: ws}
}
// SetIndexer attaches the workspace indexer for background file indexing.
// Must be called after NewIndexer is created (circular dependency break).
func (fs *FS) SetIndexer(idx *Indexer) {
fs.indexer = idx
}
// Init ensures the base workspaces directory exists.
func (fs *FS) Init() error {
return os.MkdirAll(fs.basePath, 0750)
@@ -183,6 +190,12 @@ func (fs *FS) WriteFile(ctx context.Context, w *models.Workspace, relPath string
return fmt.Errorf("workspace: refusing to overwrite symlink: %s", relPath)
}
// Check existing sha256 for content-addressed skip (v0.21.2)
var oldSHA256 string
if existing, err := fs.store.GetFile(ctx, w.ID, relPath); err == nil {
oldSHA256 = existing.SHA256
}
// Ensure parent directory exists
dir := filepath.Dir(abs)
if err := os.MkdirAll(dir, 0750); err != nil {
@@ -218,16 +231,31 @@ func (fs *FS) WriteFile(ctx context.Context, w *models.Workspace, relPath string
// Update DB index
contentType := detectContentType(relPath, abs)
hash := hex.EncodeToString(h.Sum(nil))
newHash := hex.EncodeToString(h.Sum(nil))
return fs.store.UpsertFile(ctx, &models.WorkspaceFile{
f := &models.WorkspaceFile{
WorkspaceID: w.ID,
Path: relPath,
IsDirectory: false,
ContentType: contentType,
SizeBytes: n,
SHA256: hash,
})
SHA256: newHash,
}
if err := fs.store.UpsertFile(ctx, f); err != nil {
return err
}
// Trigger async indexing if content changed (v0.21.2)
if fs.indexer != nil && newHash != oldSHA256 {
// Use workspace owner for embedding provider resolution
var teamID *string
if w.OwnerType == models.WorkspaceOwnerTeam {
teamID = &w.OwnerID
}
fs.indexer.IndexFile(w, f, w.OwnerID, teamID)
}
return nil
}
// DeleteFile removes a file or empty directory at relPath.