diff --git a/crates/core/src/backend/lock.rs b/crates/core/src/backend/lock.rs index 24c29db6..3602eb85 100644 --- a/crates/core/src/backend/lock.rs +++ b/crates/core/src/backend/lock.rs @@ -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() @@ -86,14 +95,13 @@ impl WriteBackend for LockBackend { } fn lock(&self, tpe: FileType, id: &Id, until: Option>) -> 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()?;