fix: prevent duplicate metadata storage by returning empty strings from finalize

Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-16 14:37:13 -03:00
parent 6b2cb49881
commit 31a653449c
2 changed files with 23 additions and 88 deletions

View File

@@ -52,14 +52,8 @@ impl MetaPlugin for BinaryMetaPlugin {
}
fn finalize(&mut self) -> io::Result<String> {
// 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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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<String> {
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]) {