Skip to content

Commit b505cda

Browse files
Fix cargo clippy warnings
commit-id:9e90ffc7
1 parent b451b00 commit b505cda

File tree

16 files changed

+169
-183
lines changed

16 files changed

+169
-183
lines changed

hyper_cgi/src/hyper_cgi.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub async fn do_cgi(
8484
let mut line = String::new();
8585
while stdout.read_line(&mut line).await.unwrap_or(0) > 0 {
8686
line = line
87-
.trim_end_matches("\n")
88-
.trim_end_matches("\r")
87+
.trim_end_matches('\n')
88+
.trim_end_matches('\r')
8989
.to_owned();
9090

9191
let l: Vec<&str> = line.splitn(2, ": ").collect();
@@ -95,7 +95,7 @@ pub async fn do_cgi(
9595
if l[0] == "Status" {
9696
response = response.status(
9797
hyper::StatusCode::from_u16(
98-
u16::from_str(l[1].split(" ").next().unwrap_or("500")).unwrap_or(500),
98+
u16::from_str(l[1].split(' ').next().unwrap_or("500")).unwrap_or(500),
9999
)
100100
.unwrap_or(hyper::StatusCode::INTERNAL_SERVER_ERROR),
101101
);
@@ -116,7 +116,7 @@ pub async fn do_cgi(
116116
return (response, err_output);
117117
}
118118

119-
return (error_response(), err_output);
119+
(error_response(), err_output)
120120
}
121121

122122
fn setup_cmd(cmd: &mut Command, req: &Request<hyper::Body>) {
@@ -138,24 +138,21 @@ fn setup_cmd(cmd: &mut Command, req: &Request<hyper::Body>) {
138138
"CONTENT_TYPE",
139139
req.headers()
140140
.get(hyper::header::CONTENT_TYPE)
141-
.map(|x| x.to_str().ok())
142-
.flatten()
141+
.and_then(|x| x.to_str().ok())
143142
.unwrap_or_default(),
144143
)
145144
.env(
146145
"HTTP_CONTENT_ENCODING",
147146
req.headers()
148147
.get(hyper::header::CONTENT_ENCODING)
149-
.map(|x| x.to_str().ok())
150-
.flatten()
148+
.and_then(|x| x.to_str().ok())
151149
.unwrap_or_default(),
152150
)
153151
.env(
154152
"CONTENT_LENGTH",
155153
req.headers()
156154
.get(hyper::header::CONTENT_LENGTH)
157-
.map(|x| x.to_str().ok())
158-
.flatten()
155+
.and_then(|x| x.to_str().ok())
159156
.unwrap_or_default(),
160157
);
161158
}

josh-proxy/src/auth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ impl Handle {
4242
let u = josh::ok_or!(String::from_utf8(line[6..].to_vec()), {
4343
return Ok(("".to_string(), "".to_string()));
4444
});
45-
let decoded = josh::ok_or!(base64::decode(&u), {
45+
let decoded = josh::ok_or!(base64::decode(u), {
4646
return Ok(("".to_string(), "".to_string()));
4747
});
4848
let s = josh::ok_or!(String::from_utf8(decoded), {
4949
return Ok(("".to_string(), "".to_string()));
5050
});
5151
let (username, password) = s.as_str().split_once(':').unwrap_or(("", ""));
52-
return Ok((username.to_string(), password.to_string()));
52+
Ok((username.to_string(), password.to_string()))
5353
}
5454
}
5555

@@ -65,7 +65,7 @@ pub fn add_auth(token: &str) -> josh::JoshResult<Handle> {
6565
header: Some(header),
6666
};
6767
AUTH.lock()?.insert(hp.clone(), p);
68-
return Ok(hp);
68+
Ok(hp)
6969
}
7070

7171
pub async fn check_auth(url: &str, auth: &Handle, required: bool) -> josh::JoshResult<bool> {

josh-proxy/src/bin/josh-proxy.rs

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use futures::FutureExt;
1313
use hyper::body::HttpBody;
1414
use hyper::service::{make_service_fn, service_fn};
1515
use hyper::{Request, Response, Server, StatusCode};
16-
use hyper_reverse_proxy;
16+
1717
use indoc::formatdoc;
1818
use josh::{josh_error, JoshError, JoshResult};
1919
use josh_rpc::calls::RequestedCommand;
@@ -160,7 +160,7 @@ async fn fetch_upstream(
160160
match (force, fetch_timer_ok, head_ref, head_ref_resolved) {
161161
(false, true, None, _) => return Ok(()),
162162
(false, true, Some(head_ref), _) => {
163-
if let Some(_) = resolve_cache_ref(head_ref).map_err(FetchError::from_josh_error)? {
163+
if (resolve_cache_ref(head_ref).map_err(FetchError::from_josh_error)?).is_some() {
164164
trace!("cache ref resolved");
165165
return Ok(());
166166
}
@@ -214,7 +214,7 @@ async fn fetch_upstream(
214214

215215
std::mem::drop(permit);
216216

217-
if let Ok(_) = fetch_result {
217+
if fetch_result.is_ok() {
218218
fetch_timers.write()?.insert(key, std::time::Instant::now());
219219
}
220220

@@ -365,7 +365,7 @@ async fn do_filter(
365365
let name = format!(
366366
"refs/josh/upstream/{}/{}",
367367
&josh::to_ns(&meta.config.repo),
368-
headref.clone()
368+
headref
369369
);
370370
if let Ok(r) = transaction.repo().revparse_single(&name) {
371371
refslist.push((headref.clone(), r.id()));
@@ -387,10 +387,10 @@ async fn do_filter(
387387
let t2 = josh::cache::Transaction::open(&repo_path.join("overlay"), None)?;
388388
t2.repo()
389389
.odb()?
390-
.add_disk_alternate(&repo_path.join("mirror").join("objects").to_str().unwrap())?;
390+
.add_disk_alternate(repo_path.join("mirror").join("objects").to_str().unwrap())?;
391391
let updated_refs = josh::filter_refs(&t2, filter, &refslist, josh::filter::empty())?;
392392
let mut updated_refs = josh_proxy::refs_locking(updated_refs, &meta);
393-
josh::housekeeping::namespace_refs(&mut updated_refs, &temp_ns.name());
393+
josh::housekeeping::namespace_refs(&mut updated_refs, temp_ns.name());
394394
josh::update_refs(&t2, &mut updated_refs, &temp_ns.reference(&headref));
395395
t2.repo()
396396
.reference_symbolic(
@@ -454,7 +454,7 @@ async fn handle_ui_request(
454454
.request(&req)
455455
.build(result)?;
456456

457-
return Ok(response);
457+
Ok(response)
458458
}
459459

460460
async fn query_meta_repo(
@@ -473,7 +473,7 @@ async fn query_meta_repo(
473473
match fetch_upstream(
474474
serv.clone(),
475475
meta_repo.to_owned(),
476-
&remote_auth,
476+
remote_auth,
477477
remote_url.to_owned(),
478478
Some("HEAD"),
479479
None,
@@ -489,7 +489,7 @@ async fn query_meta_repo(
489489

490490
let transaction = josh::cache::Transaction::open(
491491
&serv.repo_path.join("mirror"),
492-
Some(&format!("refs/josh/upstream/{}/", &josh::to_ns(&meta_repo),)),
492+
Some(&format!("refs/josh/upstream/{}/", &josh::to_ns(meta_repo),)),
493493
)?;
494494

495495
let meta_tree = transaction
@@ -500,11 +500,11 @@ async fn query_meta_repo(
500500
let meta_blob = josh::filter::tree::get_blob(
501501
transaction.repo(),
502502
&meta_tree,
503-
&std::path::Path::new(&upstream_repo.trim_start_matches("/")).join("config.yml"),
503+
&std::path::Path::new(&upstream_repo.trim_start_matches('/')).join("config.yml"),
504504
);
505505

506-
if meta_blob == "" {
507-
return Err(josh::josh_error(&"meta repo entry not found"));
506+
if meta_blob.is_empty() {
507+
return Err(josh::josh_error("meta repo entry not found"));
508508
}
509509

510510
let mut meta: josh_proxy::MetaConfig = Default::default();
@@ -515,16 +515,16 @@ async fn query_meta_repo(
515515
let meta_blob = josh::filter::tree::get_blob(
516516
transaction.repo(),
517517
&meta_tree,
518-
&std::path::Path::new(&upstream_repo.trim_start_matches("/")).join("lock.yml"),
518+
&std::path::Path::new(&upstream_repo.trim_start_matches('/')).join("lock.yml"),
519519
);
520520

521-
if meta_blob == "" {
522-
return Err(josh::josh_error(&"locked refs not found"));
521+
if meta_blob.is_empty() {
522+
return Err(josh::josh_error("locked refs not found"));
523523
}
524524
meta.refs_lock = serde_yaml::from_str(&meta_blob)?;
525525
}
526526

527-
return Ok(meta);
527+
Ok(meta)
528528
}
529529

530530
async fn make_meta_config(
@@ -699,7 +699,7 @@ async fn serve_namespace(
699699
stdout_stream.flush().await
700700
};
701701

702-
copy_future.await.map_err(|e| ServeError::FifoError(e))
702+
copy_future.await.map_err(ServeError::FifoError)
703703
};
704704

705705
let write_stdin = async {
@@ -722,7 +722,7 @@ async fn serve_namespace(
722722
copy_result = copy_future => {
723723
copy_result
724724
.map(|_| ())
725-
.map_err(|e| ServeError::FifoError(e))
725+
.map_err(ServeError::FifoError)
726726
}
727727
_ = stdin_cancel_token.cancelled() => {
728728
Ok(())
@@ -781,7 +781,7 @@ async fn serve_namespace(
781781

782782
fn is_repo_blocked(meta: &MetaConfig) -> bool {
783783
let block = std::env::var("JOSH_REPO_BLOCK").unwrap_or("".to_owned());
784-
let block = block.split(";").collect::<Vec<_>>();
784+
let block = block.split(';').collect::<Vec<_>>();
785785

786786
for b in block {
787787
if b == meta.config.repo {
@@ -948,7 +948,7 @@ async fn handle_serve_namespace_request(
948948
Ok(filter) => filter,
949949
Err(e) => {
950950
return Ok(make_response(
951-
hyper::Body::from(format!("Failed to parse filter: {}", e.to_string())),
951+
hyper::Body::from(format!("Failed to parse filter: {}", e)),
952952
StatusCode::BAD_REQUEST,
953953
))
954954
}
@@ -958,13 +958,13 @@ async fn handle_serve_namespace_request(
958958
query_filter,
959959
match &ARGS.filter_prefix {
960960
Some(filter_prefix) => {
961-
let filter_prefix = match josh::filter::parse(&filter_prefix) {
961+
let filter_prefix = match josh::filter::parse(filter_prefix) {
962962
Ok(filter) => filter,
963963
Err(e) => {
964964
return Ok(make_response(
965965
hyper::Body::from(format!(
966966
"Failed to parse prefix filter passed as command line argument: {}",
967-
e.to_string()
967+
e
968968
)),
969969
StatusCode::SERVICE_UNAVAILABLE,
970970
))
@@ -1036,7 +1036,7 @@ async fn call_service(
10361036
if let Some(parsed_url) = FilteredRepoUrl::from_str(&path) {
10371037
let mut pu = parsed_url;
10381038

1039-
if pu.rest.starts_with(":") {
1039+
if pu.rest.starts_with(':') {
10401040
let guessed_url = path.trim_end_matches("/info/refs");
10411041
return Ok(make_response(
10421042
hyper::Body::from(formatdoc!(
@@ -1224,7 +1224,7 @@ async fn call_service(
12241224
git_ns: temp_ns.name().to_string(),
12251225
git_dir: repo_path.clone(),
12261226
mirror_git_dir: mirror_repo_path.clone(),
1227-
context_propagator: context_propagator,
1227+
context_propagator,
12281228
};
12291229

12301230
let mut cmd = Command::new("git");
@@ -1281,8 +1281,7 @@ async fn serve_query(
12811281

12821282
let transaction = josh::cache::Transaction::open(&serv.repo_path.join("overlay"), None)?;
12831283
transaction.repo().odb()?.add_disk_alternate(
1284-
&serv
1285-
.repo_path
1284+
serv.repo_path
12861285
.join("mirror")
12871286
.join("objects")
12881287
.to_str()
@@ -1300,7 +1299,7 @@ async fn serve_query(
13001299
.in_current_span()
13011300
.await?;
13021301

1303-
return Ok(match res {
1302+
Ok(match res {
13041303
Ok(Some(res)) => Response::builder()
13051304
.status(hyper::StatusCode::OK)
13061305
.body(hyper::Body::from(res))?,
@@ -1312,7 +1311,7 @@ async fn serve_query(
13121311
Err(res) => Response::builder()
13131312
.status(hyper::StatusCode::UNPROCESSABLE_ENTITY)
13141313
.body(hyper::Body::from(res.to_string()))?,
1315-
});
1314+
})
13161315
}
13171316

13181317
#[tracing::instrument]
@@ -1538,10 +1537,7 @@ fn update_hook(refname: &str, old: &str, new: &str) -> josh::JoshResult<i32> {
15381537

15391538
let client = reqwest::blocking::Client::builder().timeout(None).build()?;
15401539
let resp = client
1541-
.post(&format!(
1542-
"http://localhost:{}/repo_update",
1543-
repo_update.port
1544-
))
1540+
.post(format!("http://localhost:{}/repo_update", repo_update.port))
15451541
.json(&repo_update)
15461542
.send();
15471543

@@ -1587,8 +1583,7 @@ async fn serve_graphql(
15871583
)?;
15881584
let transaction = josh::cache::Transaction::open(&serv.repo_path.join("overlay"), None)?;
15891585
transaction.repo().odb()?.add_disk_alternate(
1590-
&serv
1591-
.repo_path
1586+
serv.repo_path
15921587
.join("mirror")
15931588
.join("objects")
15941589
.to_str()
@@ -1677,8 +1672,7 @@ async fn serve_graphql(
16771672
)?;
16781673
josh_proxy::push_head_url(
16791674
context.transaction.lock()?.repo(),
1680-
&serv
1681-
.repo_path
1675+
serv.repo_path
16821676
.join("mirror")
16831677
.join("objects")
16841678
.to_str()
@@ -1687,15 +1681,15 @@ async fn serve_graphql(
16871681
&refname,
16881682
&remote_url,
16891683
&remote_auth,
1690-
&temp_ns.name(),
1684+
temp_ns.name(),
16911685
"META_PUSH",
16921686
false,
16931687
)?;
16941688
Ok(())
16951689
})
16961690
.in_current_span()
16971691
.await??;
1698-
return Ok(gql_result);
1692+
Ok(gql_result)
16991693
}
17001694

17011695
async fn shutdown_signal() {

josh-proxy/src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ pub fn parse_args() -> josh::JoshResult<Args> {
127127
let remote = args
128128
.get_many::<String>("remote")
129129
.ok_or(josh_error("no remote specified"))?
130-
.map(|s| s.clone())
130+
.cloned()
131131
.collect::<Vec<_>>();
132132
let remote = parse_remotes(&remote)?;
133133

134134
let local = args
135135
.get_one::<String>("local")
136-
.ok_or(josh_error(&"missing local directory"))?
136+
.ok_or(josh_error("missing local directory"))?
137137
.clone();
138138

139139
let poll_user = args.get_one::<String>("poll").map(String::clone);
@@ -145,7 +145,7 @@ pub fn parse_args() -> josh::JoshResult<Args> {
145145

146146
let filter_prefix = args.get_one::<String>("filter-prefix").map(String::clone);
147147

148-
return Ok(Args {
148+
Ok(Args {
149149
remote,
150150
local,
151151
poll_user,
@@ -156,7 +156,7 @@ pub fn parse_args() -> josh::JoshResult<Args> {
156156
cache_duration,
157157
static_resource_proxy_target,
158158
filter_prefix,
159-
});
159+
})
160160
}
161161

162162
pub fn parse_args_or_exit(code: i32) -> Args {

0 commit comments

Comments
 (0)