github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libdokan/fso.go (about) 1 // Copyright 2016 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package libdokan 6 7 import ( 8 "sync/atomic" 9 "time" 10 11 "github.com/keybase/client/go/kbfs/dokan" 12 "github.com/keybase/client/go/kbfs/libkbfs" 13 "golang.org/x/net/context" 14 ) 15 16 // FSO is a common type for file system objects, i.e. Dirs or Files. 17 type FSO struct { 18 refcount refcount // nolint -- it's used when embedded in dir/file 19 name string // KBFS name, not encoded for windows 20 folder *Folder 21 node libkbfs.Node 22 parent libkbfs.Node 23 emptyFile 24 } 25 26 // SetFileTime sets mtime for FSOs (File and Dir). TLFs have a separate SetFileTime. 27 func (f *FSO) SetFileTime(ctx context.Context, fi *dokan.FileInfo, creation time.Time, lastAccess time.Time, lastWrite time.Time) (err error) { 28 f.folder.fs.logEnter(ctx, "FSO SetFileTime") 29 defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }() 30 f.folder.fs.log.CDebugf(ctx, "FSO SetFileTime %v %v %v", creation, lastAccess, lastWrite) 31 32 if !lastWrite.IsZero() { 33 return f.folder.fs.config.KBFSOps().SetMtime(ctx, f.node, &lastWrite) 34 } 35 36 return nil 37 } 38 39 type refcount struct { 40 x int32 41 } 42 43 func (rc *refcount) Increase() { 44 atomic.AddInt32(&rc.x, 1) 45 } 46 47 func (rc *refcount) Decrease() bool { 48 return atomic.AddInt32(&rc.x, -1) == 0 49 }