Skip to content

Commit

Permalink
Merge branch 'main' into ipblock46
Browse files Browse the repository at this point in the history
  • Loading branch information
partim committed Jul 9, 2024
2 parents e618d1e + 19188c9 commit 4371634
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ New

* `ca::idexchange::Error` now impls `std::error::Error`. ([#297])
* Re-export `bcder` as `dep::bcder` if it is enabled. ([#299])
* Added `PublisherRequest::set_publisher_handle?. ([#300])
* Added `PublisherRequest::set_publisher_handle`. ([#300])
* Added `uri::{Rsync,Https}::path_into_dir` ([#302])

Bug fixes

Expand All @@ -20,6 +21,7 @@ Other changes
[#299]: https://github.com/NLnetLabs/rpki-rs/pull/299
[#300]: https://github.com/NLnetLabs/rpki-rs/pull/300
[#301]: https://github.com/NLnetLabs/rpki-rs/pull/301
[#302]: https://github.com/NLnetLabs/rpki-rs/pull/302


## 0.18.4
Expand Down
31 changes: 31 additions & 0 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ impl Rsync {
&self.bytes[self.path_start..]
}

/// Converts the URI into one representing a directory.
///
/// If the path does not end in a slash or is not empty, appends a slash
/// to it.
pub fn path_into_dir(&mut self) {
if !self.path_is_dir() {
let mut new_bytes = Vec::with_capacity(self.bytes.len() + 1);
new_bytes.extend_from_slice(&self.bytes);
new_bytes.push(b'/');
self.bytes = new_bytes.into();
}
}

/// Returns the parent URI.
///
/// The parent URI is the URI with the last path segment removed. If a
Expand Down Expand Up @@ -598,6 +611,24 @@ impl Https {
&self.as_str()[self.path_idx..]
}

/// Returns whether the URI's path resolves to a directory.
pub fn path_is_dir(&self) -> bool {
self.path().is_empty() || self.path().ends_with('/')
}

/// Converts the URI into one representing a directory.
///
/// If the path does not end in a slash or is not empty, appends a slash
/// to it.
pub fn path_into_dir(&mut self) {
if !self.path_is_dir() {
let mut new_bytes = Vec::with_capacity(self.uri.len() + 1);
new_bytes.extend_from_slice(&self.uri);
new_bytes.push(b'/');
self.uri = new_bytes.into();
}
}

/// This function will join this URI and the given path. If the current
/// URI does not end with a trailing '/', it will be injected.
pub fn join(&self, path: &[u8]) -> Result<Self, Error> {
Expand Down

0 comments on commit 4371634

Please sign in to comment.