Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions component/attr_cache/attr_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (suite *attrCacheTestSuite) assertNotInCache(path string) {
}

func (suite *attrCacheTestSuite) addPathToCache(path string, metadata bool) {
isDir := path[len(path)-1] == '/'
isDir := strings.HasSuffix(path, "/")
path = internal.TruncateDirName(path)
pathAttr := getPathAttr(path, defaultSize, fs.FileMode(defaultMode), metadata)
if isDir {
Expand Down Expand Up @@ -241,7 +241,7 @@ func generateNestedPathAttr(path string, size int64, mode os.FileMode) []*intern
pathAttrs := make([]*internal.ObjAttr, 0)
for p := a.Front(); p != nil; p = p.Next() {
pString := p.Value.(string)
isDir := pString[len(pString)-1] == '/'
isDir := strings.HasSuffix(pString, "/")
pString = internal.TruncateDirName(pString)
newPathAttr := getPathAttr(pString, size, mode, true)
if isDir {
Expand Down Expand Up @@ -1321,7 +1321,7 @@ func (suite *attrCacheTestSuite) TestSyncDir() {
// directory cache is enabled, so a dir paths should NOT be invalid
for p := a.Front(); p != nil; p = p.Next() {
path := p.Value.(string)
isDir := path[len(path)-1] == '/'
isDir := strings.HasSuffix(path, "/")
truncatedPath = internal.TruncateDirName(path)
if isDir {
suite.assertUntouched(truncatedPath)
Expand Down
3 changes: 1 addition & 2 deletions component/azstorage/block_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,7 @@ func (bb *BlockBlob) List(

func (bb *BlockBlob) getListPath(prefix string) string {
listPath := bb.getFormattedPath(prefix)
if (prefix != "" && prefix[len(prefix)-1] == '/') ||
(prefix == "" && bb.Config.prefixPath != "") {
if strings.HasSuffix(prefix, "/") || (prefix == "" && bb.Config.prefixPath != "") {
listPath += "/"
}
return listPath
Expand Down
2 changes: 1 addition & 1 deletion component/s3storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (cl *Client) RenameDirectory(source string, target string) error {
// If name is a directory, the trailing slash is optional.
func (cl *Client) GetAttr(name string) (*internal.ObjAttr, error) {
log.Trace("Client::GetAttr : name %s", name)
explicitDirLookup := len(name) > 0 && name[len(name)-1] == '/'
explicitDirLookup := strings.HasSuffix(name, "/")
dirName := internal.ExtendDirName(name)

// first let's suppose the caller is looking for a file
Expand Down
6 changes: 2 additions & 4 deletions component/s3storage/s3wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,14 @@ func (cl *Client) List(
// combine the configured prefix and the prefix being given to List to get a full listPath
listPath := cl.getKey(prefix, false, false)
// replace any trailing forward slash stripped by common.JoinUnixFilepath
if (prefix != "" && prefix[len(prefix)-1] == '/') ||
(prefix == "" && cl.Config.prefixPath != "") {
if strings.HasSuffix(prefix, "/") || (prefix == "" && cl.Config.prefixPath != "") {
listPath += "/"
}

// Only look for CommonPrefixes (subdirectories) if List was called with a prefix ending in a slash.
// If prefix does not end in a slash, CommonPrefixes would find unwanted results.
// For example, it would find "filet-of-fish/" when searching for "file".
// Check for an empty path to prevent indexing to [-1]
findCommonPrefixes := listPath == "" || listPath[len(listPath)-1] == '/'
findCommonPrefixes := strings.HasSuffix(listPath, "/")

var nextMarker *string
var token *string
Expand Down
14 changes: 3 additions & 11 deletions internal/component_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package internal

import (
"os"
"strings"

"github.com/Seagate/cloudfuse/internal/handlemap"
)
Expand Down Expand Up @@ -198,20 +199,11 @@ type CommittedBlock struct {
type CommittedBlockList []CommittedBlock

func TruncateDirName(name string) string {
if len(name) == 0 {
return ""
}
if name[len(name)-1:] == "/" {
name = name[:len(name)-1]
}
return name
return strings.TrimSuffix(name, "/")
}

func ExtendDirName(name string) string {
if len(name) == 0 {
return "/"
}
if name[len(name)-1:] != "/" {
if !strings.HasSuffix(name, "/") {
name = name + "/"
}
return name
Expand Down
Loading