internal/rosa: do not keep underlying file
All checks were successful
Test / Create distribution (push) Successful in 58s
Test / Sandbox (push) Successful in 2m34s
Test / Hakurei (push) Successful in 3m40s
Test / ShareFS (push) Successful in 3m49s
Test / Sandbox (race detector) (push) Successful in 4m55s
Test / Hakurei (race detector) (push) Successful in 5m54s
Test / Flake checks (push) Successful in 1m29s
All checks were successful
Test / Create distribution (push) Successful in 58s
Test / Sandbox (push) Successful in 2m34s
Test / Hakurei (push) Successful in 3m40s
Test / ShareFS (push) Successful in 3m49s
Test / Sandbox (race detector) (push) Successful in 4m55s
Test / Hakurei (race detector) (push) Successful in 5m54s
Test / Flake checks (push) Successful in 1m29s
No operation require further filesystem interaction for now. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -105,9 +105,9 @@ func WriteReport(msg message.Msg, w io.Writer, c *pkg.Cache) error {
|
||||
|
||||
// Report provides efficient access to a report file populated by [WriteReport].
|
||||
type Report struct {
|
||||
// Underlying file, must not be exposed directly.
|
||||
f *os.File
|
||||
// Slice backed by f. Access must be prepared by HandleAccess.
|
||||
// Slice backed by the underlying file.
|
||||
//
|
||||
// Access must be prepared by HandleAccess.
|
||||
data []byte
|
||||
|
||||
// Offsets into data for each identifier.
|
||||
@@ -121,31 +121,31 @@ type Report struct {
|
||||
|
||||
// OpenReport opens a file populated by [WriteReport]
|
||||
func OpenReport(pathname string) (rp *Report, err error) {
|
||||
var r Report
|
||||
if r.f, err = os.Open(pathname); err != nil {
|
||||
var f *os.File
|
||||
if f, err = os.Open(pathname); err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
_ = r.f.Close()
|
||||
if r.data != nil {
|
||||
_ = syscall.Munmap(r.data)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
var fi os.FileInfo
|
||||
if fi, err = r.f.Stat(); err != nil {
|
||||
if fi, err = f.Stat(); err != nil {
|
||||
_ = f.Close()
|
||||
return
|
||||
}
|
||||
|
||||
var r Report
|
||||
if r.data, err = syscall.Mmap(
|
||||
int(r.f.Fd()),
|
||||
int(f.Fd()),
|
||||
0,
|
||||
int(fi.Size()),
|
||||
syscall.PROT_READ,
|
||||
syscall.MAP_PRIVATE,
|
||||
); err != nil {
|
||||
_ = f.Close()
|
||||
return
|
||||
}
|
||||
|
||||
if err = f.Close(); err != nil {
|
||||
_ = r.Close()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -230,9 +230,6 @@ func (r *Report) ArtifactOf(id unique.Handle[pkg.ID]) (status []byte, n int64) {
|
||||
|
||||
// Close closes the underlying file and releases all associated resources.
|
||||
func (r *Report) Close() error {
|
||||
r.closeOnce.Do(func() {
|
||||
err := syscall.Munmap(r.data)
|
||||
r.closeErr = errors.Join(err, r.f.Close())
|
||||
})
|
||||
r.closeOnce.Do(func() { r.closeErr = syscall.Munmap(r.data) })
|
||||
return r.closeErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user