fusefrontend: use sync.Once for one-time warnings

Using a simple boolean was racy (which was harmless
in this case) and non-idomatic.
This commit is contained in:
Jakob Unterwurzacher 2016-05-29 22:50:03 +02:00
parent fd53dfd2ad
commit 1648c54adb
2 changed files with 9 additions and 11 deletions

View File

@ -472,15 +472,14 @@ func (f *file) GetAttr(a *fuse.Attr) fuse.Status {
return fuse.OK return fuse.OK
} }
// Allocate - FUSE call, fallocate(2) // Only warn once
var allocateWarned bool var allocateWarnOnce sync.Once
// Allocate - FUSE call, fallocate(2)
func (f *file) Allocate(off uint64, sz uint64, mode uint32) fuse.Status { func (f *file) Allocate(off uint64, sz uint64, mode uint32) fuse.Status {
// Only warn once allocateWarnOnce.Do(func() {
if !allocateWarned {
toggledlog.Warn.Printf("fallocate(2) is not supported, returning ENOSYS - see https://github.com/rfjakob/gocryptfs/issues/1") toggledlog.Warn.Printf("fallocate(2) is not supported, returning ENOSYS - see https://github.com/rfjakob/gocryptfs/issues/1")
allocateWarned = true })
}
return fuse.ENOSYS return fuse.ENOSYS
} }

View File

@ -208,14 +208,13 @@ func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context)
return fs.FileSystem.Mknod(cPath, mode, dev, context) return fs.FileSystem.Mknod(cPath, mode, dev, context)
} }
var truncateWarned bool // Only warn once
var truncateWarnOnce sync.Once
func (fs *FS) Truncate(path string, offset uint64, context *fuse.Context) (code fuse.Status) { func (fs *FS) Truncate(path string, offset uint64, context *fuse.Context) (code fuse.Status) {
// Only warn once truncateWarnOnce.Do(func() {
if !truncateWarned {
toggledlog.Warn.Printf("truncate(2) is not supported, returning ENOSYS - use ftruncate(2)") toggledlog.Warn.Printf("truncate(2) is not supported, returning ENOSYS - use ftruncate(2)")
truncateWarned = true })
}
return fuse.ENOSYS return fuse.ENOSYS
} }