MMap.Name() should return the SHM name not the full filesystem path
This commit is contained in:
parent
6ace082bc2
commit
2d1a2c30bf
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -51,7 +52,8 @@ type MMap interface {
|
|||||||
Unlink() error
|
Unlink() error
|
||||||
Slice() []byte
|
Slice() []byte
|
||||||
Name() string
|
Name() string
|
||||||
IsFilesystemBacked() bool
|
IsFileSystemBacked() bool
|
||||||
|
FileSystemName() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccessFlags int
|
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 {
|
func (self *file_based_mmap) Name() string {
|
||||||
|
return filepath.Base(self.f.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *file_based_mmap) FileSystemName() string {
|
||||||
return self.f.Name()
|
return self.f.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +137,7 @@ func (self *file_based_mmap) Unlink() (err error) {
|
|||||||
return os.Remove(self.f.Name())
|
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) {
|
func CreateTemp(pattern string, size uint64) (MMap, error) {
|
||||||
return create_temp(pattern, size)
|
return create_temp(pattern, size)
|
||||||
|
|||||||
@ -108,7 +108,8 @@ func (self *syscall_based_mmap) Unlink() (err error) {
|
|||||||
return shm_unlink(self.Name())
|
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) {
|
func create_temp(pattern string, size uint64) (ans MMap, err error) {
|
||||||
var prefix, suffix string
|
var prefix, suffix string
|
||||||
|
|||||||
@ -48,8 +48,8 @@ func TestSHM(t *testing.T) {
|
|||||||
if err == nil {
|
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()))
|
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() {
|
if mm.IsFileSystemBacked() {
|
||||||
_, err = os.Stat(mm.Name())
|
_, err = os.Stat(mm.FileSystemName())
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
t.Fatalf("Unlinking %s did not work", mm.Name())
|
t.Fatalf("Unlinking %s did not work", mm.Name())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user