github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libfuse/journal_control_file.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 //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 // JournalControlFile is a special file used to control journal 19 // settings. 20 type JournalControlFile struct { 21 folder *Folder 22 action libfs.JournalAction 23 } 24 25 var _ fs.Node = (*JournalControlFile)(nil) 26 27 // Attr implements the fs.Node interface for JournalControlFile. 28 func (f *JournalControlFile) 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 = (*JournalControlFile)(nil) 35 36 var _ fs.HandleWriter = (*JournalControlFile)(nil) 37 38 // Write implements the fs.HandleWriter interface for JournalControlFile. 39 func (f *JournalControlFile) Write(ctx context.Context, req *fuse.WriteRequest, 40 resp *fuse.WriteResponse) (err error) { 41 f.folder.fs.log.CDebugf(ctx, "JournalControlFile (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 jManager, err := libkbfs.GetJournalManager(f.folder.fs.config) 49 if err != nil { 50 return err 51 } 52 53 err = f.action.Execute( 54 ctx, jManager, f.folder.getFolderBranch().Tlf, f.folder.h) 55 if err != nil { 56 return err 57 } 58 59 resp.Size = len(req.Data) 60 return nil 61 }