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].
|
// Report provides efficient access to a report file populated by [WriteReport].
|
||||||
type Report struct {
|
type Report struct {
|
||||||
// Underlying file, must not be exposed directly.
|
// Slice backed by the underlying file.
|
||||||
f *os.File
|
//
|
||||||
// Slice backed by f. Access must be prepared by HandleAccess.
|
// Access must be prepared by HandleAccess.
|
||||||
data []byte
|
data []byte
|
||||||
|
|
||||||
// Offsets into data for each identifier.
|
// Offsets into data for each identifier.
|
||||||
@@ -121,31 +121,31 @@ type Report struct {
|
|||||||
|
|
||||||
// OpenReport opens a file populated by [WriteReport]
|
// OpenReport opens a file populated by [WriteReport]
|
||||||
func OpenReport(pathname string) (rp *Report, err error) {
|
func OpenReport(pathname string) (rp *Report, err error) {
|
||||||
var r Report
|
var f *os.File
|
||||||
if r.f, err = os.Open(pathname); err != nil {
|
if f, err = os.Open(pathname); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
_ = r.f.Close()
|
|
||||||
if r.data != nil {
|
|
||||||
_ = syscall.Munmap(r.data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
var fi os.FileInfo
|
var fi os.FileInfo
|
||||||
if fi, err = r.f.Stat(); err != nil {
|
if fi, err = f.Stat(); err != nil {
|
||||||
|
_ = f.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var r Report
|
||||||
if r.data, err = syscall.Mmap(
|
if r.data, err = syscall.Mmap(
|
||||||
int(r.f.Fd()),
|
int(f.Fd()),
|
||||||
0,
|
0,
|
||||||
int(fi.Size()),
|
int(fi.Size()),
|
||||||
syscall.PROT_READ,
|
syscall.PROT_READ,
|
||||||
syscall.MAP_PRIVATE,
|
syscall.MAP_PRIVATE,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
_ = f.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = f.Close(); err != nil {
|
||||||
|
_ = r.Close()
|
||||||
return
|
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.
|
// Close closes the underlying file and releases all associated resources.
|
||||||
func (r *Report) Close() error {
|
func (r *Report) Close() error {
|
||||||
r.closeOnce.Do(func() {
|
r.closeOnce.Do(func() { r.closeErr = syscall.Munmap(r.data) })
|
||||||
err := syscall.Munmap(r.data)
|
|
||||||
r.closeErr = errors.Join(err, r.f.Close())
|
|
||||||
})
|
|
||||||
return r.closeErr
|
return r.closeErr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user