azureblob: fix handling of objects with // in #5858

This commit is contained in:
Nick Craig-Wood 2025-01-02 18:34:46 +00:00
parent 81ecfb0f64
commit 39b8f17ebb

View File

@ -790,6 +790,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
SetTier: true, SetTier: true,
GetTier: true, GetTier: true,
ServerSideAcrossConfigs: true, ServerSideAcrossConfigs: true,
DoubleSlash: true,
}).Fill(ctx, f) }).Fill(ctx, f)
if opt.DirectoryMarkers { if opt.DirectoryMarkers {
f.features.CanHaveEmptyDirectories = true f.features.CanHaveEmptyDirectories = true
@ -1135,7 +1136,7 @@ func (f *Fs) list(ctx context.Context, containerName, directory, prefix string,
if prefix != "" { if prefix != "" {
prefix += "/" prefix += "/"
} }
if directory != "" { if directory != "" && (prefix == "" && !bucket.IsAllSlashes(directory) || prefix != "" && !strings.HasSuffix(directory, "/")) {
directory += "/" directory += "/"
} }
delimiter := "" delimiter := ""
@ -1211,18 +1212,22 @@ func (f *Fs) list(ctx context.Context, containerName, directory, prefix string,
} }
// Send the subdirectories // Send the subdirectories
foundItems += len(response.Segment.BlobPrefixes) foundItems += len(response.Segment.BlobPrefixes)
for _, remote := range response.Segment.BlobPrefixes { for _, blobPrefix := range response.Segment.BlobPrefixes {
if remote.Name == nil { if blobPrefix.Name == nil {
fs.Debugf(f, "Nil prefix received") fs.Debugf(f, "Nil prefix received")
continue continue
} }
remote := strings.TrimRight(*remote.Name, "/") remote := f.opt.Enc.ToStandardPath(*blobPrefix.Name)
remote = f.opt.Enc.ToStandardPath(remote)
if !strings.HasPrefix(remote, prefix) { if !strings.HasPrefix(remote, prefix) {
fs.Debugf(f, "Odd directory name received %q", remote) fs.Debugf(f, "Odd directory name received %q", remote)
continue continue
} }
remote = remote[len(prefix):] remote = remote[len(prefix):]
// Trim one slash off the remote name
remote, _ = strings.CutSuffix(remote, "/")
if remote == "" || bucket.IsAllSlashes(remote) {
remote += "/"
}
if addContainer { if addContainer {
remote = path.Join(containerName, remote) remote = path.Join(containerName, remote)
} }
@ -2152,6 +2157,11 @@ func (o *Object) getTags() (tags map[string]string) {
// getBlobSVC creates a blob client // getBlobSVC creates a blob client
func (o *Object) getBlobSVC() *blob.Client { func (o *Object) getBlobSVC() *blob.Client {
container, directory := o.split() container, directory := o.split()
// If we are trying to remove an all / directory marker then
// this will have one / too many now.
if bucket.IsAllSlashes(o.remote) {
directory = strings.TrimSuffix(directory, "/")
}
return o.fs.getBlobSVC(container, directory) return o.fs.getBlobSVC(container, directory)
} }