github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libdokan/prefetch_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  	"github.com/keybase/client/go/kbfs/dokan"
     9  	"github.com/keybase/client/go/kbfs/libkbfs"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // PrefetchFile represents a write-only file where any write of at least one
    14  // byte triggers either disabling or enabling prefetching.  It is mainly useful
    15  // for testing.
    16  type PrefetchFile struct {
    17  	fs     *FS
    18  	enable bool
    19  	specialWriteFile
    20  }
    21  
    22  // WriteFile performs writes for dokan.
    23  func (f *PrefetchFile) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
    24  	f.fs.logEnter(ctx, "PrefetchFile WriteFile")
    25  	defer func() { f.fs.reportErr(ctx, libkbfs.WriteMode, err) }()
    26  	f.fs.log.CDebugf(ctx, "PrefetchFile (enable: %t) Write", f.enable)
    27  	if len(bs) == 0 {
    28  		return 0, nil
    29  	}
    30  
    31  	f.fs.config.BlockOps().TogglePrefetcher(f.enable)
    32  
    33  	return len(bs), err
    34  }