github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libdokan/reclaim_quota_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  // ReclaimQuotaFile represents a write-only file when any write of at
    14  // least one byte triggers a quota reclamation of the folder.
    15  type ReclaimQuotaFile struct {
    16  	folder *Folder
    17  	specialWriteFile
    18  }
    19  
    20  // WriteFile implements writes for dokan. Note a write triggers quota
    21  // reclamation, but does not wait for it to finish. If you want to
    22  // wait, write to SyncFromServerFileName.
    23  func (f *ReclaimQuotaFile) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
    24  	f.folder.fs.logEnter(ctx, "ReclaimQuotaFile Write")
    25  	defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()
    26  	if len(bs) == 0 {
    27  		return 0, nil
    28  	}
    29  	err = libkbfs.ForceQuotaReclamationForTesting(
    30  		f.folder.fs.config, f.folder.getFolderBranch())
    31  	return len(bs), err
    32  }