github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libdokan/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  package libdokan
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/keybase/client/go/kbfs/dokan"
    11  	"github.com/keybase/client/go/kbfs/libfs"
    12  	"github.com/keybase/client/go/kbfs/libkbfs"
    13  	"golang.org/x/net/context"
    14  )
    15  
    16  // JournalControlFile is a special file used to control journal
    17  // settings.
    18  type JournalControlFile struct {
    19  	specialWriteFile
    20  	folder *Folder
    21  	action libfs.JournalAction
    22  }
    23  
    24  // WriteFile implements writes for dokan.
    25  func (f *JournalControlFile) WriteFile(ctx context.Context,
    26  	fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
    27  	f.folder.fs.logEnter(ctx,
    28  		fmt.Sprintf("JournalQuotaFile (f.action=%s) Write", f.action))
    29  	defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()
    30  	if len(bs) == 0 {
    31  		return 0, nil
    32  	}
    33  
    34  	jManager, err := libkbfs.GetJournalManager(f.folder.fs.config)
    35  	if err != nil {
    36  		return 0, err
    37  	}
    38  
    39  	err = f.action.Execute(
    40  		ctx, jManager, f.folder.getFolderBranch().Tlf, f.folder.h)
    41  	if err != nil {
    42  		return 0, err
    43  	}
    44  
    45  	return len(bs), nil
    46  }