Skip to content

Commit

Permalink
better parameters for command
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Sep 29, 2024
1 parent 0fea41b commit 8c31493
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions crates/core/src/backend/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ impl ReadBackend for LockBackend {
}
}

fn path(tpe: FileType, id: &Id) -> String {
let hex_id = id.to_hex();
match tpe {
FileType::Config => "config".into(),
FileType::Pack => format!("data/{}/{}", &hex_id[0..2], &*hex_id),
_ => format!("{}/{}", tpe.dirname(), &*hex_id),
}
}

impl WriteBackend for LockBackend {
fn create(&self) -> Result<()> {
self.be.create()
Expand All @@ -86,14 +95,13 @@ impl WriteBackend for LockBackend {
}

fn lock(&self, tpe: FileType, id: &Id, until: Option<DateTime<Local>>) -> Result<()> {
let until = until.map_or_else(|| String::new(), |u| format!("{}", u.to_rfc3339()));
let path = path(tpe, id);
let args = self.command.args().iter().map(|c| {
let mut c = c
.replace("%id", &id.to_string())
.replace("%type", tpe.dirname());
if let Some(until) = until {
c = c.replace("%until", &until.to_string());
}
c
c.replace("%id", &id.to_string())
.replace("%type", tpe.dirname())
.replace("%path", &path)
.replace("%until", &until)
});
debug!("calling {:?}...", self.command);
let status = Command::new(self.command.command()).args(args).status()?;
Expand Down

0 comments on commit 8c31493

Please sign in to comment.