Skip to content

Commit c2f62aa

Browse files
committed
Windows-only: refresh open directories using notifications
1 parent a8a20b0 commit c2f62aa

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

internal/cfg/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type FlagStorage struct {
106106
PreferPatchUploads bool
107107
NoPreloadDir bool
108108
NoVerifySSL bool
109+
WinRefreshDirs bool
109110

110111
// Debugging
111112
DebugMain bool

internal/cfg/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ MISC OPTIONS:
140140
Value: gid,
141141
Usage: "Drop root group and change to this group ID (defaults to --gid).",
142142
},
143+
144+
cli.BoolFlag{
145+
Name: "refresh-dirs",
146+
Usage: "Automatically refresh open directories using notifications under Windows",
147+
},
143148
}
144149

145150
s3Flags := []cli.Flag{
@@ -845,6 +850,7 @@ func PopulateFlags(c *cli.Context) (ret *FlagStorage) {
845850
Gid: uint32(c.Int("gid")),
846851
Setuid: c.Int("setuid"),
847852
Setgid: c.Int("setgid"),
853+
WinRefreshDirs: c.Bool("refresh-dirs"),
848854

849855
// Tuning,
850856
MemoryLimit: uint64(1024*1024*c.Int("memory-limit")),

internal/goofys_windows.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func NewGoofysWin(fs *Goofys) *GoofysWin {
7676
fs.NotifyCallback = func(notifications []interface{}) {
7777
go fsint.Notify(notifications)
7878
}
79+
if fs.flags.WinRefreshDirs {
80+
go fsint.WinDirRefresher()
81+
}
7982
return fsint
8083
}
8184

@@ -995,6 +998,34 @@ func (fs *GoofysWin) Notify(notifications []interface{}) {
995998
}
996999
}
9971000

1001+
func (fs *GoofysWin) WinDirRefresher() {
1002+
for atomic.LoadInt32(&fs.shutdown) == 0 {
1003+
select {
1004+
case <-time.After(1 * time.Second):
1005+
case <-fs.shutdownCh:
1006+
return
1007+
}
1008+
fs.mu.Lock()
1009+
var dirs []*Inode
1010+
for _, dh := range fs.dirHandles {
1011+
dirs = append(dirs, dh.inode)
1012+
}
1013+
fs.mu.Unlock()
1014+
expireUnix := time.Now().Add(-fs.flags.StatCacheTTL)
1015+
notifications := make(map[string]struct{})
1016+
for _, dir := range dirs {
1017+
dir.mu.Lock()
1018+
if dir.Parent != nil && dir.dir.DirTime.Before(expireUnix) {
1019+
notifications["/"+dir.FullName()] = struct{}{}
1020+
}
1021+
dir.mu.Unlock()
1022+
}
1023+
for dir := range notifications {
1024+
fs.host.Notify(dir, fuse.NOTIFY_CHMOD | fuse.NOTIFY_CHOWN | fuse.NOTIFY_UTIME | fuse.NOTIFY_CHFLAGS | fuse.NOTIFY_TRUNCATE)
1025+
}
1026+
}
1027+
}
1028+
9981029
// Mount the file system based on the supplied arguments, returning a
9991030
// MountedFS that can be joined to wait for unmounting.
10001031
func MountWin(

0 commit comments

Comments
 (0)