Skip to content

Commit

Permalink
Windows-only: refresh open directories using notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Nov 29, 2024
1 parent a8a20b0 commit c2f62aa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type FlagStorage struct {
PreferPatchUploads bool
NoPreloadDir bool
NoVerifySSL bool
WinRefreshDirs bool

// Debugging
DebugMain bool
Expand Down
6 changes: 6 additions & 0 deletions internal/cfg/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ MISC OPTIONS:
Value: gid,
Usage: "Drop root group and change to this group ID (defaults to --gid).",
},

cli.BoolFlag{
Name: "refresh-dirs",
Usage: "Automatically refresh open directories using notifications under Windows",
},
}

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

// Tuning,
MemoryLimit: uint64(1024*1024*c.Int("memory-limit")),
Expand Down
31 changes: 31 additions & 0 deletions internal/goofys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func NewGoofysWin(fs *Goofys) *GoofysWin {
fs.NotifyCallback = func(notifications []interface{}) {
go fsint.Notify(notifications)
}
if fs.flags.WinRefreshDirs {
go fsint.WinDirRefresher()
}
return fsint
}

Expand Down Expand Up @@ -995,6 +998,34 @@ func (fs *GoofysWin) Notify(notifications []interface{}) {
}
}

func (fs *GoofysWin) WinDirRefresher() {
for atomic.LoadInt32(&fs.shutdown) == 0 {
select {
case <-time.After(1 * time.Second):
case <-fs.shutdownCh:
return
}
fs.mu.Lock()
var dirs []*Inode
for _, dh := range fs.dirHandles {
dirs = append(dirs, dh.inode)
}
fs.mu.Unlock()
expireUnix := time.Now().Add(-fs.flags.StatCacheTTL)
notifications := make(map[string]struct{})
for _, dir := range dirs {
dir.mu.Lock()
if dir.Parent != nil && dir.dir.DirTime.Before(expireUnix) {
notifications["/"+dir.FullName()] = struct{}{}
}
dir.mu.Unlock()
}
for dir := range notifications {
fs.host.Notify(dir, fuse.NOTIFY_CHMOD | fuse.NOTIFY_CHOWN | fuse.NOTIFY_UTIME | fuse.NOTIFY_CHFLAGS | fuse.NOTIFY_TRUNCATE)
}
}
}

// Mount the file system based on the supplied arguments, returning a
// MountedFS that can be joined to wait for unmounting.
func MountWin(
Expand Down

0 comments on commit c2f62aa

Please sign in to comment.