From 1648c54adb9b7d9d8984857a35c6092bbae6bdec Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 29 May 2016 22:50:03 +0200 Subject: [PATCH] fusefrontend: use sync.Once for one-time warnings Using a simple boolean was racy (which was harmless in this case) and non-idomatic. --- internal/fusefrontend/file.go | 11 +++++------ internal/fusefrontend/fs.go | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index 33afcb9..e374956 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -472,15 +472,14 @@ func (f *file) GetAttr(a *fuse.Attr) fuse.Status { return fuse.OK } -// Allocate - FUSE call, fallocate(2) -var allocateWarned bool +// Only warn once +var allocateWarnOnce sync.Once +// Allocate - FUSE call, fallocate(2) func (f *file) Allocate(off uint64, sz uint64, mode uint32) fuse.Status { - // Only warn once - if !allocateWarned { + allocateWarnOnce.Do(func() { toggledlog.Warn.Printf("fallocate(2) is not supported, returning ENOSYS - see https://github.com/rfjakob/gocryptfs/issues/1") - allocateWarned = true - } + }) return fuse.ENOSYS } diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index 1ef88b7..988a41a 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -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) } -var truncateWarned bool +// Only warn once +var truncateWarnOnce sync.Once func (fs *FS) Truncate(path string, offset uint64, context *fuse.Context) (code fuse.Status) { - // Only warn once - if !truncateWarned { + truncateWarnOnce.Do(func() { toggledlog.Warn.Printf("truncate(2) is not supported, returning ENOSYS - use ftruncate(2)") - truncateWarned = true - } + }) return fuse.ENOSYS }