Files
sanspie a6822156cd
ci-platforms / windows amd64 smoke (push) Skipped
ci / release (push) Successful in 8m58s
ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
ci / checks (push) Successful in 4m46s
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 13m28s
Finish Stage 12 editor fixes and refreshed platformer
2026-11-05 17:36:42 +03:00

39 lines
1.1 KiB
Go

package document
import (
"io"
"io/fs"
"os"
"aego/core/errs"
"aego/core/log"
)
// OpenSource opens saved source without creating a document or reading its working journal; callers own the file and may impose format-specific streaming/size limits before decoding.
func (m *Manager) OpenSource(rel string) (fs.File, error) {
rel = Clean(rel)
if !validProjectPath(rel) {
return nil, errs.New(errs.EditorDocument, "source path must stay inside the project")
}
f, err := os.OpenInRoot(m.Abs("."), rel)
if err != nil {
return nil, errs.Wrap(err, errs.EditorDocument, "cannot open project source").With(log.F("path", rel))
}
return f, nil
}
// ReadSource reads saved source bytes, including a sidecar whose open document
// has unsaved edits. Restoring runtime artifacts must not read that dirty buffer.
func (m *Manager) ReadSource(rel string) ([]byte, error) {
f, err := m.OpenSource(rel)
if err != nil {
return nil, err
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
return nil, errs.Wrap(err, errs.EditorDocument, "cannot read project source").With(log.F("path", rel))
}
return data, nil
}