Skip to content

Commit

Permalink
fix: cleanup and borrowing/coercion
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Jan 24, 2024
1 parent 6a1d193 commit 287040d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/handlers/access_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn check_auth_and_acl(
} else {
return Err(ErrorKind::NonUnicodePath(path.display().to_string()));
};
let allowed = acl.allowed(user.as_str(), path, tpe, append);
let allowed = acl.allowed(&user, path, tpe, append);
tracing::debug!("[auth] user: {user}, path: {path}, tpe: {tpe}, allowed: {allowed}");

match allowed {
Expand Down
10 changes: 5 additions & 5 deletions src/handlers/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) async fn has_config(
tracing::debug!("[has_config] path: {path:?}, tpe: {tpe}, name: {name}");
let path_str = path.unwrap_or_default();
let path = std::path::Path::new(&path_str);
check_auth_and_acl(auth.user, tpe.as_str(), path, AccessType::Read)?;
check_auth_and_acl(auth.user, &tpe, path, AccessType::Read)?;

let storage = STORAGE.get().unwrap();
let file = storage.filename(path, &tpe, &name);
Expand Down Expand Up @@ -57,7 +57,7 @@ pub(crate) async fn add_config(
tracing::debug!("[add_config] path: {path:?}, tpe: {tpe}, name: {name}");
let path = path.unwrap_or_default();
let path = PathBuf::from(&path);
let file = get_save_file(auth.user, path, tpe.as_str(), name).await?;
let file = get_save_file(auth.user, path, &tpe, name).await?;

let stream = request.into_body().into_data_stream();
save_body(file, stream).await?;
Expand All @@ -72,13 +72,13 @@ pub(crate) async fn delete_config(
auth: AuthFromRequest,
) -> Result<impl IntoResponse> {
tracing::debug!("[delete_config] path: {path:?}, tpe: {tpe}, name: {name}");
check_name(tpe.as_str(), &name)?;
check_name(&tpe, &name)?;
let path_str = path.unwrap_or_default();
let path = Path::new(&path_str);
check_auth_and_acl(auth.user, tpe.as_str(), path, AccessType::Append)?;
check_auth_and_acl(auth.user, &tpe, path, AccessType::Append)?;

let storage = STORAGE.get().unwrap();
if storage.remove_file(path, tpe.as_str(), &name).is_err() {
if storage.remove_file(path, &tpe, &name).is_err() {
return Err(ErrorKind::RemovingFileFailed(path_str));
}
Ok(())
Expand Down
14 changes: 7 additions & 7 deletions src/handlers/file_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) async fn add_file(

//credential & access check executed in get_save_file()
let path = std::path::PathBuf::from(&path_str);
let file = get_save_file(auth.user, path, tpe.as_str(), name).await?;
let file = get_save_file(auth.user, path, &tpe, name).await?;

let stream = request.into_body().into_data_stream();
save_body(file, stream).await?;
Expand All @@ -57,12 +57,12 @@ pub(crate) async fn delete_file(
let path_str = path.unwrap_or_default();
let path = Path::new(&path_str);

check_name(tpe.as_str(), name.as_str())?;
check_auth_and_acl(auth.user, tpe.as_str(), path, AccessType::Append)?;
check_name(&tpe, &name)?;
check_auth_and_acl(auth.user, &tpe, path, AccessType::Append)?;

let storage = STORAGE.get().unwrap();

if let Err(e) = storage.remove_file(path, tpe.as_str(), name.as_str()) {
if let Err(e) = storage.remove_file(path, &tpe, &name) {
tracing::debug!("[delete_file] IO error: {e:?}");
return Err(ErrorKind::RemovingFileFailed(path_str));
}
Expand All @@ -78,11 +78,11 @@ pub(crate) async fn get_file(
) -> Result<impl IntoResponse> {
tracing::debug!("[get_file] path: {path:?}, tpe: {tpe}, name: {name}");

check_name(tpe.as_str(), name.as_str())?;
check_name(&tpe, &name)?;
let path_str = path.unwrap_or_default();
let path = Path::new(&path_str);

check_auth_and_acl(auth.user, tpe.as_str(), path, AccessType::Read)?;
check_auth_and_acl(auth.user, &tpe, path, AccessType::Read)?;

let storage = STORAGE.get().unwrap();
let file = match storage.open_file(path, &tpe, &name).await {
Expand Down Expand Up @@ -111,7 +111,7 @@ pub(crate) async fn get_save_file(
) -> Result<impl AsyncWrite + Unpin + Finalizer> {
tracing::debug!("[get_save_file] path: {path:?}, tpe: {tpe}, name: {name}");

check_name(tpe, name.as_str())?;
check_name(tpe, &name)?;
check_auth_and_acl(user, tpe, path.as_path(), AccessType::Append)?;

let storage = STORAGE.get().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/file_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) async fn file_length(
tracing::debug!("[length] path: {path:?}, tpe: {tpe}, name: {name}");
let path_str = path.unwrap_or_default();
let path = Path::new(&path_str);
check_auth_and_acl(auth.user, tpe.as_str(), path, AccessType::Read)?;
check_auth_and_acl(auth.user, &tpe, path, AccessType::Read)?;

let storage = STORAGE.get().unwrap();
let file = storage.filename(path, &tpe, &name);
Expand Down
2 changes: 0 additions & 2 deletions src/handlers/path_analysis.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::fmt::{Display, Formatter};

use serde::de;

pub mod constants {
// TPE_LOCKS is is defined, but outside this types[] array.
// This allow us to loop over the types[] when generating "routes"
Expand Down

0 comments on commit 287040d

Please sign in to comment.