Skip to content

Commit 7ded938

Browse files
authored
Replace Path::child with Path::join (#666)
* Path::join * update old uses
1 parent bdcac43 commit 7ded938

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub async fn put_get_delete_list(storage: &DynObjectStore) {
283283

284284
// "HELLO" percent encoded
285285
let hello_prefix = Path::parse("%48%45%4C%4C%4F").unwrap();
286-
let path = hello_prefix.child("foo.parquet");
286+
let path = hello_prefix.clone().join("foo.parquet");
287287

288288
storage.put(&path, vec![0, 1].into()).await.unwrap();
289289
let files = flatten_list_stream(storage, Some(&hello_prefix))

src/local.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl ObjectStore for LocalFileSystem {
526526
drop(parts);
527527

528528
if is_directory {
529-
common_prefixes.insert(prefix.child(common_prefix));
529+
common_prefixes.insert(prefix.clone().join(common_prefix));
530530
} else if let Some(metadata) = convert_entry(entry, entry_location)? {
531531
objects.push(metadata);
532532
}
@@ -1599,7 +1599,7 @@ mod tests {
15991599
let integration = LocalFileSystem::new_with_prefix(root.clone()).unwrap();
16001600

16011601
let directory = Path::from("directory");
1602-
let object = directory.child("child.txt");
1602+
let object = directory.clone().join("child.txt");
16031603
let data = Bytes::from("arbitrary");
16041604
integration.put(&object, data.clone().into()).await.unwrap();
16051605
integration.head(&object).await.unwrap();

src/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl ObjectStore for InMemory {
367367
};
368368

369369
if parts.next().is_some() {
370-
common_prefixes.insert(prefix.child(common_prefix));
370+
common_prefixes.insert(prefix.clone().join(common_prefix));
371371
} else {
372372
let object = ObjectMeta {
373373
location: k.clone(),

src/path/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,23 @@ impl Path {
360360
}
361361

362362
/// Creates a new child of this [`Path`]
363+
#[deprecated = "use .join() or .clone().join() instead"]
363364
pub fn child<'a>(&self, child: impl Into<PathPart<'a>>) -> Self {
364-
let raw = match self.raw.is_empty() {
365-
true => format!("{}", child.into().raw),
366-
false => format!("{}{}{}", self.raw, DELIMITER, child.into().raw),
365+
self.clone().join(child)
366+
}
367+
368+
/// Appends a single path segment to this [`Path`]
369+
pub fn join<'a>(self, child: impl Into<PathPart<'a>>) -> Self {
370+
let child_cow_str = child.into().raw;
371+
372+
let raw = if self.raw.is_empty() {
373+
child_cow_str.to_string()
374+
} else {
375+
use std::fmt::Write;
376+
377+
let mut raw = self.raw;
378+
write!(raw, "{DELIMITER}{child_cow_str}").expect("failed to append to string");
379+
raw
367380
};
368381

369382
Self { raw }
@@ -598,7 +611,7 @@ mod tests {
598611
);
599612

600613
// a longer prefix doesn't match
601-
let needle = haystack.child("longer now");
614+
let needle = haystack.clone().join("longer now");
602615
assert!(
603616
!haystack.prefix_matches(&needle),
604617
"{haystack:?} shouldn't have started with {needle:?}"
@@ -612,7 +625,7 @@ mod tests {
612625
);
613626

614627
// two dir prefix matches
615-
let needle = needle.child("baz%2Ftest");
628+
let needle = needle.join("baz%2Ftest");
616629
assert!(
617630
haystack.prefix_matches(&needle),
618631
"{haystack:?} should have started with {needle:?}"

src/throttle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ mod tests {
558558

559559
// create new entries
560560
for i in 0..n_entries {
561-
let path = prefix.child(i.to_string().as_str());
561+
let path = prefix.clone().join(i.to_string().as_str());
562562
store.put(&path, "bar".into()).await.unwrap();
563563
}
564564

0 commit comments

Comments
 (0)