Skip to content

Commit

Permalink
fix: fix url encode/decode bug (#628)
Browse files Browse the repository at this point in the history
Signed-off-by: Lzzzt <[email protected]>
  • Loading branch information
Lzzzzzt authored Jul 26, 2024
1 parent 97791be commit b32b685
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dragonfly-client-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tonic.workspace = true
url.workspace = true
tracing.workspace = true
opendal.workspace = true
percent-encoding.workspace = true
futures = "0.3.28"
libloading = "0.8.4"

Expand Down
8 changes: 5 additions & 3 deletions dragonfly-client-backend/src/object_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use dragonfly_api::common;
use dragonfly_client_core::error::BackendError;
use dragonfly_client_core::{Error as ClientError, Result as ClientResult};
use opendal::{raw::HttpClient, Metakey, Operator};
use percent_encoding::percent_decode_str;
use std::fmt;
use std::result::Result;
use std::str::FromStr;
Expand Down Expand Up @@ -136,14 +137,15 @@ impl TryFrom<Url> for ParsedURL {
let key = url
.path()
.strip_prefix('/')
.ok_or_else(|| ClientError::InvalidURI(url.to_string()))?
.to_string();
.ok_or_else(|| ClientError::InvalidURI(url.to_string()))?;
// Decode the key.
let decoded_key = percent_decode_str(key).decode_utf8_lossy().to_string();

Ok(Self {
url,
scheme,
bucket,
key,
key: decoded_key,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions dragonfly-client/src/bin/dfget/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ async fn download(
}
}

progress_bar.finish_with_message(format!("{} downloaded", download_path));
progress_bar.finish();
Ok(())
}

Expand Down Expand Up @@ -813,7 +813,7 @@ fn make_output_by_entry(url: Url, output: &Path, entry: DirEntry) -> Result<Path
let entry_url: Url = entry.url.parse().or_err(ErrorType::ParseError)?;
let decoded_entry_url = percent_decode_str(entry_url.path()).decode_utf8_lossy();
Ok(decoded_entry_url
.replace(root_dir.as_str(), output_root_dir.as_str())
.replacen(root_dir.as_str(), output_root_dir.as_str(), 1)
.into())
}

Expand Down

0 comments on commit b32b685

Please sign in to comment.