]> git.lizzy.rs Git - rust.git/commitdiff
dont overwrite memfies
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 26 Jan 2019 12:41:52 +0000 (15:41 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 26 Jan 2019 12:41:52 +0000 (15:41 +0300)
crates/ra_vfs/src/lib.rs
crates/ra_vfs/tests/vfs.rs

index d1b0222e79f64420767bb1ce48b85ced2966071a..70a13f7655228c8f1a1357da59ace48d06ce6d34 100644 (file)
@@ -264,7 +264,9 @@ pub fn handle_task(&mut self, task: io::TaskResult) {
                 self.pending_changes.push(change);
             }
             TaskResult::AddSingleFile { root, path, text } => {
-                self.do_add_file(root, path, text, false);
+                if self.find_file(root, &path).is_none() {
+                    self.do_add_file(root, path, text, false);
+                }
             }
             TaskResult::ChangeSingleFile { root, path, text } => {
                 if let Some(file) = self.find_file(root, &path) {
index 357e1c775e2614ec09c3a264ecc32a62239d90ab..545e1dbdd2568a561e341c0fd599fd643e72ade4 100644 (file)
@@ -165,6 +165,18 @@ fn test_vfs_works() -> std::io::Result<()> {
         assert_eq!(path, "sub1/sub2/new1.rs")
     );
 
+    {
+        vfs.add_file_overlay(&dir.path().join("a/memfile.rs"), "memfile".to_string());
+        assert_match!(
+            vfs.commit_changes().as_slice(),
+            [VfsChange::AddFile { text, .. }],
+            assert_eq!(text.as_str(), "memfile")
+        );
+        fs::write(&dir.path().join("a/memfile.rs"), "ignore me").unwrap();
+        process_tasks(&mut vfs, 1);
+        assert_match!(vfs.commit_changes().as_slice(), []);
+    }
+
     // should be ignored
     fs::create_dir_all(dir.path().join("a/target")).unwrap();
     fs::write(&dir.path().join("a/target/new.rs"), "ignore me").unwrap();