From 3d291da0f69378768eb51e0f7f41d655106e0009 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 13 Dec 2022 10:45:40 +0000 Subject: [PATCH] azureblob: fix directory marker detection after SDK upgrade When the SDK was upgraded it started delivering metadata where the keys were not in lower case as per the old SDK. Rclone normalises the case of the keys for storage in the Object, but the directory marker check was being done with the unnormalised keys as it needs to be done before the Object is created. This fixes the directory marker check to do a case insensitive compare of the metadata keys. --- backend/azureblob/azureblob.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index dae8405a0..80050a991 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -988,13 +988,18 @@ func (o *Object) updateMetadataWithModTime(modTime time.Time) { func isDirectoryMarker(size int64, metadata map[string]string, remote string) bool { // Directory markers are 0 length if size == 0 { - // Note that metadata with hdi_isfolder = true seems to be a - // defacto standard for marking blobs as directories. endsWithSlash := strings.HasSuffix(remote, "/") - if endsWithSlash || remote == "" || metadata["hdi_isfolder"] == "true" { + if endsWithSlash || remote == "" { return true } - + // Note that metadata with hdi_isfolder = true seems to be a + // defacto standard for marking blobs as directories. + // Note also that the metadata hasn't been normalised to lower case yet + for k, v := range metadata { + if strings.EqualFold(k, "hdi_isfolder") && v == "true" { + return true + } + } } return false } @@ -1007,13 +1012,18 @@ func isDirectoryMarker(size int64, metadata map[string]string, remote string) bo func isDirectoryMarkerP(size int64, metadata map[string]*string, remote string) bool { // Directory markers are 0 length if size == 0 { - // Note that metadata with hdi_isfolder = true seems to be a - // defacto standard for marking blobs as directories. endsWithSlash := strings.HasSuffix(remote, "/") - if endsWithSlash || remote == "" || (metadata["hdi_isfolder"] != nil && *metadata["hdi_isfolder"] == "true") { + if endsWithSlash || remote == "" { return true } - + // Note that metadata with hdi_isfolder = true seems to be a + // defacto standard for marking blobs as directories. + // Note also that the metadata hasn't been normalised to lower case yet + for k, pv := range metadata { + if strings.EqualFold(k, "hdi_isfolder") && pv != nil && *pv == "true" { + return true + } + } } return false }