github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libdokan/rekey_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  // RekeyFile represents a write-only file when any write of at least
    14  // one byte triggers a rekey of the folder.
    15  type RekeyFile struct {
    16  	folder *Folder
    17  	specialWriteFile
    18  }
    19  
    20  // WriteFile implements writes for dokan.
    21  func (f *RekeyFile) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
    22  	f.folder.fs.logEnter(ctx, "RekeyFile Write")
    23  	defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()
    24  	if len(bs) == 0 {
    25  		return 0, nil
    26  	}
    27  	_, err = libkbfs.RequestRekeyAndWaitForOneFinishEvent(ctx,
    28  		f.folder.fs.config.KBFSOps(), f.folder.getFolderBranch().Tlf)
    29  	if err != nil {
    30  		return 0, err
    31  	}
    32  	f.folder.fs.NotificationGroupWait()
    33  	return len(bs), nil
    34  }