diff --git a/src/io/edit_lock.rs b/src/io/edit_lock.rs index 512a7c66f..0065cbebe 100644 --- a/src/io/edit_lock.rs +++ b/src/io/edit_lock.rs @@ -134,7 +134,13 @@ impl EditLease { ); let _ = sidecar.flush(); - let (drawing, platform_warning) = acquire_drawing_lock(&canonical)?; + let (drawing, platform_warning) = match acquire_drawing_lock(&canonical) { + Ok(lock) => lock, + Err(error) => { + let _ = std::fs::remove_file(&lock_path); + return Err(error); + } + }; Ok(Self { _sidecar: sidecar, drawing, @@ -162,6 +168,14 @@ impl EditLease { } } +impl Drop for EditLease { + fn drop(&mut self) { + // Remove the path while the exclusive sidecar lock is still held so + // another editor cannot acquire it during cleanup. + let _ = std::fs::remove_file(&self.lock_path); + } +} + fn acquire_drawing_lock(path: &Path) -> Result<(Option, Option), EditLeaseError> { let drawing = match OpenOptions::new().read(true).write(true).open(path) { Ok(file) => file,