handle files with no referrer

This commit is contained in:
Robin Appelman 2025-10-13 19:11:04 +02:00
commit 3c393a5f5e

View file

@ -81,8 +81,8 @@ fn help() {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Packet { struct Packet {
path: String, path: String,
origin: String, origin: Option<String>,
referrer: String, referrer: Option<String>,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -91,16 +91,12 @@ struct Response {
} }
fn set_attr(packet: Packet) -> Result<(), IoError> { fn set_attr(packet: Packet) -> Result<(), IoError> {
xattr::set( if let Some(origin) = packet.origin {
&packet.path, xattr::set(&packet.path, "user.xdg.origin.url", origin.as_bytes())?;
"user.xdg.origin.url", }
packet.origin.as_bytes(), if let Some(referrer) = packet.referrer {
)?; xattr::set(&packet.path, "user.xdg.referrer.url", referrer.as_bytes())?;
xattr::set( }
&packet.path,
"user.xdg.referrer.url",
packet.referrer.as_bytes(),
)?;
Ok(()) Ok(())
} }