Skip to content

Commit 0ccdb91

Browse files
committed
fix: treat the URL to walk as a directory.
1 parent d8d6d08 commit 0ccdb91

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,13 @@ pub fn rewrite_url<'a>(config: &Config, url: &'a Url) -> Result<Cow<'a, Url>> {
730730
/// Returns a list of relative paths from the given URL.
731731
///
732732
/// If the given storage URL is not a directory, an empty list is returned.
733-
pub async fn walk(config: Config, client: HttpClient, url: Url) -> Result<Vec<String>> {
733+
pub async fn walk(config: Config, client: HttpClient, mut url: Url) -> Result<Vec<String>> {
734+
if let Ok(mut segments) = url.path_segments_mut() {
735+
// Push an empty segment to treat the URL as a directory
736+
// This ensures there is no leading slash in the returned relative paths.
737+
segments.pop_if_empty().push("");
738+
}
739+
734740
if AzureBlobStorageBackend::is_supported_url(&config, &url) {
735741
let url = AzureBlobStorageBackend::rewrite_url(&config, &url)?;
736742
AzureBlobStorageBackend::new(config, client, None)
@@ -747,7 +753,7 @@ pub async fn walk(config: Config, client: HttpClient, url: Url) -> Result<Vec<St
747753
.walk(url.into_owned())
748754
.await
749755
} else {
750-
Ok(Default::default())
756+
Err(Error::UnsupportedUrl(url))
751757
}
752758
}
753759

tests/copy.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,7 @@ async fn walk() -> Result<()> {
621621
let files = cloud_copy::walk(config.clone(), client.clone(), url)
622622
.await
623623
.expect("should walk");
624-
assert_eq!(
625-
files,
626-
&["/0", "/1", "/2", "/3", "/4", "/5", "/6", "/7", "/8", "/9"]
627-
);
624+
assert_eq!(files, &["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
628625
}
629626

630627
Ok(())

0 commit comments

Comments
 (0)