github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libdokan/sync_control_file.go (about)

     1  // Copyright 2017 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  // SyncControlFile is a special file used to control sync
    17  // settings.
    18  type SyncControlFile struct {
    19  	specialWriteFile
    20  	folder *Folder
    21  	action libfs.SyncAction
    22  }
    23  
    24  // WriteFile implements writes for dokan.
    25  func (f *SyncControlFile) 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("SyncControlFile (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  	err = f.action.Execute(
    35  		ctx, f.folder.fs.config, f.folder.getFolderBranch(), f.folder.h)
    36  	if err != nil {
    37  		return 0, err
    38  	}
    39  
    40  	return len(bs), nil
    41  }