diff --git a/src/meta_plugin/system.rs b/src/meta_plugin/system.rs index 72e1546..0d81fa8 100644 --- a/src/meta_plugin/system.rs +++ b/src/meta_plugin/system.rs @@ -52,14 +52,8 @@ impl MetaPlugin for BinaryMetaPlugin { } fn finalize(&mut self) -> io::Result { - // If we already saved during IO, don't save again - if self.is_saved { - // Return the current value to avoid errors, but it won't be saved again - let is_binary = is_binary(&self.buffer); - return Ok(if is_binary { "true".to_string() } else { "false".to_string() }); - } - let is_binary = is_binary(&self.buffer); - Ok(if is_binary { "true".to_string() } else { "false".to_string() }) + // Since we save during initialize() or update(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, data: &[u8]) { @@ -123,13 +117,8 @@ impl MetaPlugin for CwdMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - match env::current_dir() { - Ok(path) => Ok(path.to_string_lossy().to_string()), - Err(_) => Ok("unknown".to_string()), - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -176,10 +165,8 @@ impl MetaPlugin for UidMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - Ok(get_current_uid().to_string()) + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -223,13 +210,8 @@ impl MetaPlugin for UserMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - match get_current_username() { - Some(username) => Ok(username.to_string_lossy().to_string()), - None => Ok("unknown".to_string()), - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -276,10 +258,8 @@ impl MetaPlugin for GidMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - Ok(get_current_gid().to_string()) + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -323,13 +303,8 @@ impl MetaPlugin for GroupMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - match get_current_groupname() { - Some(groupname) => Ok(groupname.to_string_lossy().to_string()), - None => Ok("unknown".to_string()), - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -376,13 +351,8 @@ impl MetaPlugin for ShellMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - match env::var("SHELL") { - Ok(shell) => Ok(shell), - Err(_) => Ok("unknown".to_string()), - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -429,13 +399,8 @@ impl MetaPlugin for ShellPidMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - match env::var("PPID") { - Ok(ppid) => Ok(ppid), - Err(_) => Ok(process::id().to_string()), - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -482,10 +447,8 @@ impl MetaPlugin for KeepPidMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - Ok(process::id().to_string()) + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -529,13 +492,8 @@ impl MetaPlugin for HostnameMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - match gethostname().into_string() { - Ok(hostname) => Ok(hostname), - Err(_) => Ok("unknown".to_string()), - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { @@ -582,31 +540,8 @@ impl MetaPlugin for FullHostnameMetaPlugin { } fn finalize(&mut self) -> io::Result { - if self.is_saved { - return Ok("".to_string()); // Already saved, return empty to avoid duplicate - } - // Try to get the FQDN through reverse DNS lookup - match local_ip() { - Ok(my_local_ip) => { - match lookup_addr(&my_local_ip) { - Ok(hostname) => Ok(hostname), - Err(_) => { - // Fall back to regular hostname if reverse DNS fails - match gethostname().into_string() { - Ok(hostname) => Ok(hostname), - Err(_) => Ok("unknown".to_string()), - } - } - } - } - Err(_) => { - // Fall back to regular hostname if we can't get local IP - match gethostname().into_string() { - Ok(hostname) => Ok(hostname), - Err(_) => Ok("unknown".to_string()), - } - } - } + // Since we save during initialize(), return empty to avoid duplicate saves + Ok("".to_string()) } fn update(&mut self, _data: &[u8]) { diff --git a/src/modes/save.rs b/src/modes/save.rs index fad4ddb..1d73ad5 100644 --- a/src/modes/save.rs +++ b/src/modes/save.rs @@ -213,7 +213,7 @@ fn process_input_stream( for meta_plugin in meta_plugins.iter_mut() { match meta_plugin.finalize() { Ok(value) => { - // Only save non-empty values (empty means already saved) + // Only save non-empty values (empty means already saved during initialize/update) if !value.is_empty() { if let Err(e) = meta_plugin.save_meta(conn, item_id, value) { eprintln!("Warning: Failed to save meta value: {}", e);