michal/tit

Browse tree · Show commit · Download archive

Diff

5b357f28b44b04522e55d9d1

src/instance.rs

Mode 100644100644; object a20d4eb225dbb1f1d86028ae

@@ -12,7 +12,7 @@
 pub(crate) const REPOSITORY_DIRECTORY: &str = "repositories";
 
 pub(crate) struct InstanceLock {
-    _file: File,
+    file: File,
 }
 
 impl InstanceLock {
@@ -40,10 +40,16 @@
             })?;
         validate_private_file(&path, &file)?;
         match file.try_lock() {
-            Ok(()) => Ok(Self { _file: file }),
+            Ok(()) => Ok(Self { file }),
             Err(TryLockError::WouldBlock) => Err(InstanceError::Locked),
             Err(TryLockError::Error(source)) => Err(InstanceError::Open { path, source }),
         }
+    }
+}
+
+impl Drop for InstanceLock {
+    fn drop(&mut self) {
+        let _ = self.file.unlock();
     }
 }