mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-01 22:12:04 +03:00
ensure key is file
This commit is contained in:
parent
c75cf09bcf
commit
e70cf60cca
@ -14,10 +14,16 @@ impl From<controller::UpdateError> for Error {
|
||||
fn from(value: controller::UpdateError) -> Self {
|
||||
match value {
|
||||
controller::UpdateError::Validation(
|
||||
controller::UpdateValidationError::KeyNotFound(path)
|
||||
controller::UpdateValidationError::KeyNotFound(path),
|
||||
) => Error::UserError {
|
||||
code: Code::Projects,
|
||||
message: format!("key '{}' not found", path.display()),
|
||||
message: format!("'{}' not found", path.display()),
|
||||
},
|
||||
controller::UpdateError::Validation(controller::UpdateValidationError::KeyNotFile(
|
||||
path,
|
||||
)) => Error::UserError {
|
||||
code: Code::Projects,
|
||||
message: format!("'{}' is not a file", path.display()),
|
||||
},
|
||||
controller::UpdateError::NotFound => Error::UserError {
|
||||
code: Code::Projects,
|
||||
|
@ -92,13 +92,23 @@ impl Controller {
|
||||
}
|
||||
|
||||
pub async fn update(&self, project: &UpdateRequest) -> Result<Project, UpdateError> {
|
||||
if let Some(super::AuthKey::Local { private_key_path, .. }) = &project.preferred_key {
|
||||
if let Some(super::AuthKey::Local {
|
||||
private_key_path, ..
|
||||
}) = &project.preferred_key
|
||||
{
|
||||
use resolve_path::PathResolveExt;
|
||||
let private_key_path = private_key_path.resolve();
|
||||
|
||||
if !private_key_path.exists() {
|
||||
return Err(UpdateError::Validation(
|
||||
UpdateValidationError::KeyNotFound(private_key_path.to_path_buf()),
|
||||
));
|
||||
return Err(UpdateError::Validation(UpdateValidationError::KeyNotFound(
|
||||
private_key_path.to_path_buf(),
|
||||
)));
|
||||
}
|
||||
|
||||
if !private_key_path.is_file() {
|
||||
return Err(UpdateError::Validation(UpdateValidationError::KeyNotFile(
|
||||
private_key_path.to_path_buf(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,6 +232,8 @@ pub enum UpdateError {
|
||||
pub enum UpdateValidationError {
|
||||
#[error("{0} not found")]
|
||||
KeyNotFound(path::PathBuf),
|
||||
#[error("{0} is not a file")]
|
||||
KeyNotFile(path::PathBuf),
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
Loading…
Reference in New Issue
Block a user