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