From 93b70b20993a2ddb602b0b59dea362828abec2fa Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Tue, 14 Apr 2026 09:06:35 +0800 Subject: [PATCH] fix: return os.ErrClosed on double Close() in MemMapFs MemMapFs File.Close() silently succeeds when called multiple times, while OsFs returns an error. This inconsistency causes bugs to go undetected in tests using MemMapFs that only surface in production with OsFs. Return os.ErrClosed when the file is already closed, matching the behavior of os.File. Fixes #567 --- mem/file.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mem/file.go b/mem/file.go index c77fcd40..a1ef2e66 100644 --- a/mem/file.go +++ b/mem/file.go @@ -128,6 +128,10 @@ func (f *File) Open() error { func (f *File) Close() error { f.fileData.Lock() + if f.closed { + f.fileData.Unlock() + return os.ErrClosed + } f.closed = true if !f.readOnly { setModTime(f.fileData, time.Now())