github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfuse/sync_control_file.go (about) 1 // Copyright 2017 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 //go:build !windows 6 // +build !windows 7 8 package libfuse 9 10 import ( 11 "bazil.org/fuse" 12 "bazil.org/fuse/fs" 13 "github.com/keybase/client/go/kbfs/libfs" 14 "github.com/keybase/client/go/kbfs/libkbfs" 15 "golang.org/x/net/context" 16 ) 17 18 // SyncControlFile is a special file used to control sync 19 // settings. 20 type SyncControlFile struct { 21 folder *Folder 22 action libfs.SyncAction 23 } 24 25 var _ fs.Node = (*SyncControlFile)(nil) 26 27 // Attr implements the fs.Node interface for SyncControlFile. 28 func (f *SyncControlFile) Attr(ctx context.Context, a *fuse.Attr) error { 29 a.Size = 0 30 a.Mode = 0222 31 return nil 32 } 33 34 var _ fs.Handle = (*SyncControlFile)(nil) 35 36 var _ fs.HandleWriter = (*SyncControlFile)(nil) 37 38 // Write implements the fs.HandleWriter interface for SyncControlFile. 39 func (f *SyncControlFile) Write(ctx context.Context, req *fuse.WriteRequest, 40 resp *fuse.WriteResponse) (err error) { 41 f.folder.fs.log.CDebugf(ctx, "SyncControlFile (f.action=%s) Write", 42 f.action) 43 defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }() 44 if len(req.Data) == 0 { 45 return nil 46 } 47 48 err = f.action.Execute( 49 ctx, f.folder.fs.config, f.folder.getFolderBranch(), f.folder.h) 50 if err != nil { 51 return err 52 } 53 54 resp.Size = len(req.Data) 55 return nil 56 }