MMap.Name() should return the SHM name not the full filesystem path

This commit is contained in:
Kovid Goyal 2022-12-22 11:36:11 +05:30
parent 6ace082bc2
commit 2d1a2c30bf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt"
"math/rand"
"os"
"path/filepath"
"strconv"
"strings"
@ -51,7 +52,8 @@ type MMap interface {
Unlink() error
Slice() []byte
Name() string
IsFilesystemBacked() bool
IsFileSystemBacked() bool
FileSystemName() string
}
type AccessFlags int
@ -107,6 +109,10 @@ func file_mmap(f *os.File, size uint64, access AccessFlags, truncate bool) (MMap
}
func (self *file_based_mmap) Name() string {
return filepath.Base(self.f.Name())
}
func (self *file_based_mmap) FileSystemName() string {
return self.f.Name()
}
@ -131,7 +137,7 @@ func (self *file_based_mmap) Unlink() (err error) {
return os.Remove(self.f.Name())
}
func (self *file_based_mmap) IsFilesystemBacked() bool { return true }
func (self *file_based_mmap) IsFileSystemBacked() bool { return true }
func CreateTemp(pattern string, size uint64) (MMap, error) {
return create_temp(pattern, size)

View File

@ -108,7 +108,8 @@ func (self *syscall_based_mmap) Unlink() (err error) {
return shm_unlink(self.Name())
}
func (self *syscall_based_mmap) IsFilesystemBacked() bool { return false }
func (self *syscall_based_mmap) IsFileSystemBacked() bool { return false }
func (self *syscall_based_mmap) FileSystemName() string { return "" }
func create_temp(pattern string, size uint64) (ans MMap, err error) {
var prefix, suffix string

View File

@ -48,8 +48,8 @@ func TestSHM(t *testing.T) {
if err == nil {
t.Fatalf("Unlinking failed could re-open the SHM data. Data equal: %v Data length: %d", reflect.DeepEqual(g.Slice(), data), len(g.Slice()))
}
if mm.IsFilesystemBacked() {
_, err = os.Stat(mm.Name())
if mm.IsFileSystemBacked() {
_, err = os.Stat(mm.FileSystemName())
if !errors.Is(err, fs.ErrNotExist) {
t.Fatalf("Unlinking %s did not work", mm.Name())
}