fix: crates
This commit is contained in:
parent
ea70650c45
commit
eb3e637462
15 changed files with 487 additions and 14 deletions
|
@ -1,5 +1,8 @@
|
|||
use std::{
|
||||
collections::HashMap, fs, process::{Command, Stdio}, time::Duration
|
||||
collections::HashMap,
|
||||
fs::{self, remove_file},
|
||||
process::{Command, Stdio},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use dbus::{
|
||||
|
@ -11,7 +14,7 @@ use log::{debug, error, info, trace};
|
|||
use resolve_path::PathResolveExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{tags::Tag};
|
||||
use crate::tags::Tag;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Actions {
|
||||
|
@ -36,6 +39,7 @@ pub struct CommandAction {
|
|||
pub struct LinkAction {
|
||||
pub src: String,
|
||||
pub dest: String,
|
||||
overwrite: Option<bool>,
|
||||
}
|
||||
|
||||
impl CommandAction {
|
||||
|
@ -44,7 +48,7 @@ impl CommandAction {
|
|||
command: command.into(),
|
||||
user: user.into(),
|
||||
description: None,
|
||||
require: None
|
||||
require: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,16 +78,25 @@ impl CommandAction {
|
|||
|
||||
impl LinkAction {
|
||||
pub fn link(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
trace!("linking from {:?} to {:?}...", &self.src.resolve(), &self.dest.resolve());
|
||||
trace!(
|
||||
"linking from {:?} to {:?}...",
|
||||
&self.src.resolve(),
|
||||
&self.dest.resolve()
|
||||
);
|
||||
if let Ok(existing) = fs::read_link(&self.dest.resolve()) {
|
||||
if existing == self.src.resolve() {
|
||||
debug!("link OK");
|
||||
return Ok(());
|
||||
} else {
|
||||
return Err("Destination is linked to a different path".into());
|
||||
if self.overwrite.unwrap_or(false) == true {
|
||||
debug!("removing {}...", self.dest);
|
||||
remove_file(self.dest.resolve())?;
|
||||
} else {
|
||||
return Err("Destination is linked to a different path".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
std::os::unix::fs::symlink(&self.src.resolve(), &self.dest.resolve())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ pub struct CrateManifest {
|
|||
pub struct CrateInfo {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub author: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue