github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libdokan/fakeroot.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  	"github.com/keybase/client/go/kbfs/dokan"
     9  	"github.com/keybase/client/go/libkb"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  type fakeRoot struct {
    14  	EmptyFolder
    15  }
    16  
    17  func openFakeRoot(ctx context.Context, fs *FS, fi *dokan.FileInfo) (dokan.File, dokan.CreateStatus, error) {
    18  	path := fi.Path()
    19  	fs.vlog.CLogf(ctx, libkb.VLog1, "openFakeRoot %q", path)
    20  	switch path {
    21  	case `\` + WrongUserErrorFileName:
    22  		return stringReadFile(WrongUserErrorContents), dokan.ExistingFile, nil
    23  	case `\`:
    24  		return &fakeRoot{}, dokan.ExistingDir, nil
    25  	}
    26  	return nil, 0, dokan.ErrAccessDenied
    27  }
    28  
    29  // FindFiles for dokan.
    30  func (fr *fakeRoot) FindFiles(ctx context.Context, fi *dokan.FileInfo, ignored string, callback func(*dokan.NamedStat) error) (err error) {
    31  	var ns dokan.NamedStat
    32  	ns.FileAttributes = dokan.FileAttributeNormal | dokan.FileAttributeReadonly
    33  	ns.Name = WrongUserErrorFileName
    34  	ns.FileSize = int64(len(WrongUserErrorContents))
    35  	return callback(&ns)
    36  }