github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfuse/alias.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  //go:build !windows
     6  // +build !windows
     7  
     8  package libfuse
     9  
    10  import (
    11  	"os"
    12  
    13  	"bazil.org/fuse"
    14  	"bazil.org/fuse/fs"
    15  	"golang.org/x/net/context"
    16  )
    17  
    18  // Alias represents an alias. A use case for it is a top-level folder accessed
    19  // through its non-canonical name.
    20  type Alias struct {
    21  	// The real path this alias points to. In case of TLF alias, this is the
    22  	// canonical name for the folder.
    23  	realPath string
    24  	inode    uint64
    25  }
    26  
    27  var _ fs.Node = (*Alias)(nil)
    28  
    29  // Attr implements the fs.Node interface for Alias.
    30  func (*Alias) Attr(ctx context.Context, a *fuse.Attr) error {
    31  	a.Mode = os.ModeSymlink | 0777
    32  	// Aliases can't be moved, so let bazil generate an inode.
    33  	return nil
    34  }
    35  
    36  var _ fs.NodeReadlinker = (*Alias)(nil)
    37  
    38  // Readlink implements the fs.NodeReadlinker interface for Alias.
    39  func (a *Alias) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
    40  	return a.realPath, nil
    41  }