changeset 283:e338f6ad2353

mem_env: Implement correct semantics for lock()
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 25 Sep 2017 20:31:44 +0200
parents 90db3ae63a17
children e9e304fa9ee8
files src/mem_env.rs
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/mem_env.rs	Mon Sep 25 20:31:27 2017 +0200
+++ b/src/mem_env.rs	Mon Sep 25 20:31:44 2017 +0200
@@ -220,7 +220,14 @@
                     Ok(FileLock { id: path_to_string(p) })
                 }
             }
-            Entry::Vacant(_) => err(StatusCode::NotFound, "not found"),
+            Entry::Vacant(v) => {
+                let f = MemFile::new();
+                v.insert(MemFSEntry {
+                    f: f.clone(),
+                    locked: true,
+                });
+                Ok(FileLock { id: path_to_string(p) })
+            }
         }
     }
     fn unlock_(&self, l: FileLock) -> Result<()> {
@@ -509,8 +516,8 @@
 
         // Non-existent files.
         let p2 = Path::new("/a/lock2");
-        assert!(fs.lock_(p2).is_err());
-        assert!(fs.unlock_(env::FileLock { id: "/a/lock2".to_string() }).is_err());
+        assert!(fs.lock_(p2).is_ok());
+        assert!(fs.unlock_(env::FileLock { id: "/a/lock2".to_string() }).is_ok());
     }
 
     #[test]
@@ -539,7 +546,7 @@
         assert!(me.rename(nonexist, p1).is_err());
 
         me.unlock(me.lock(p3).unwrap());
-        assert!(me.lock(nonexist).is_err());
+        assert!(me.lock(nonexist).is_ok());
 
         me.new_logger(p1).unwrap();
         assert!(me.micros() > 0);