local: use atomic types
This commit is contained in:
parent
4341d472aa
commit
a56c11753a
2 changed files with 6 additions and 6 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ type Fs struct {
|
||||||
precision time.Duration // precision of local filesystem
|
precision time.Duration // precision of local filesystem
|
||||||
warnedMu sync.Mutex // used for locking access to 'warned'.
|
warnedMu sync.Mutex // used for locking access to 'warned'.
|
||||||
warned map[string]struct{} // whether we have warned about this string
|
warned map[string]struct{} // whether we have warned about this string
|
||||||
xattrSupported int32 // whether xattrs are supported (atomic access)
|
xattrSupported atomic.Int32 // whether xattrs are supported
|
||||||
|
|
||||||
// do os.Lstat or os.Stat
|
// do os.Lstat or os.Stat
|
||||||
lstat func(name string) (os.FileInfo, error)
|
lstat func(name string) (os.FileInfo, error)
|
||||||
|
@ -291,7 +292,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
|
||||||
lstat: os.Lstat,
|
lstat: os.Lstat,
|
||||||
}
|
}
|
||||||
if xattrSupported {
|
if xattrSupported {
|
||||||
f.xattrSupported = 1
|
f.xattrSupported.Store(1)
|
||||||
}
|
}
|
||||||
f.root = cleanRootPath(root, f.opt.NoUNC, f.opt.Enc)
|
f.root = cleanRootPath(root, f.opt.NoUNC, f.opt.Enc)
|
||||||
f.features = (&fs.Features{
|
f.features = (&fs.Features{
|
||||||
|
|
|
@ -6,7 +6,6 @@ package local
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/xattr"
|
"github.com/pkg/xattr"
|
||||||
|
@ -28,7 +27,7 @@ func (f *Fs) xattrIsNotSupported(err error) bool {
|
||||||
// Xattrs not supported can be ENOTSUP or ENOATTR or EINVAL (on Solaris)
|
// Xattrs not supported can be ENOTSUP or ENOATTR or EINVAL (on Solaris)
|
||||||
if xattrErr.Err == syscall.EINVAL || xattrErr.Err == syscall.ENOTSUP || xattrErr.Err == xattr.ENOATTR {
|
if xattrErr.Err == syscall.EINVAL || xattrErr.Err == syscall.ENOTSUP || xattrErr.Err == xattr.ENOATTR {
|
||||||
// Show xattrs not supported
|
// Show xattrs not supported
|
||||||
if atomic.CompareAndSwapInt32(&f.xattrSupported, 1, 0) {
|
if f.xattrSupported.CompareAndSwap(1, 0) {
|
||||||
fs.Errorf(f, "xattrs not supported - disabling: %v", err)
|
fs.Errorf(f, "xattrs not supported - disabling: %v", err)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -41,7 +40,7 @@ func (f *Fs) xattrIsNotSupported(err error) bool {
|
||||||
// It doesn't return any attributes owned by this backend in
|
// It doesn't return any attributes owned by this backend in
|
||||||
// metadataKeys
|
// metadataKeys
|
||||||
func (o *Object) getXattr() (metadata fs.Metadata, err error) {
|
func (o *Object) getXattr() (metadata fs.Metadata, err error) {
|
||||||
if !xattrSupported || atomic.LoadInt32(&o.fs.xattrSupported) == 0 {
|
if !xattrSupported || o.fs.xattrSupported.Load() == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
var list []string
|
var list []string
|
||||||
|
@ -90,7 +89,7 @@ func (o *Object) getXattr() (metadata fs.Metadata, err error) {
|
||||||
//
|
//
|
||||||
// It doesn't set any attributes owned by this backend in metadataKeys
|
// It doesn't set any attributes owned by this backend in metadataKeys
|
||||||
func (o *Object) setXattr(metadata fs.Metadata) (err error) {
|
func (o *Object) setXattr(metadata fs.Metadata) (err error) {
|
||||||
if !xattrSupported || atomic.LoadInt32(&o.fs.xattrSupported) == 0 {
|
if !xattrSupported || o.fs.xattrSupported.Load() == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for k, value := range metadata {
|
for k, value := range metadata {
|
||||||
|
|
Loading…
Reference in a new issue