diff options
-rw-r--r-- | lesana/collection.py | 12 | ||||
-rw-r--r-- | tests/test_collection.py | 25 |
2 files changed, 31 insertions, 6 deletions
diff --git a/lesana/collection.py b/lesana/collection.py index d2f029d..457b732 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -421,12 +421,12 @@ class Collection(object): xapian.DB_CREATE_OR_OPEN ) for uid in uids: - entry = self.entry_from_uid(uid) - if entry is not None: - cache.delete_document(entry.idterm) - os.remove(os.path.join(self.itemdir, entry.fname)) - else: - logging.warning("No such entry: {}, ignoring".format(uid)) + for entry in self.entries_from_short_uid(uid): + if entry is not None: + cache.delete_document(entry.idterm) + os.remove(os.path.join(self.itemdir, entry.fname)) + else: + logging.warning("No such entry: {}, ignoring".format(uid)) cache.commit() cache.close() diff --git a/tests/test_collection.py b/tests/test_collection.py index 4160c5e..ab6d807 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -412,6 +412,31 @@ class testCollectionCreation(unittest.TestCase): mset = collection._enquire.get_mset(0, 10) self.assertEqual(mset.get_matches_estimated(), 0) + def test_partial_deletion(self): + tmpdir = tempfile.mkdtemp() + shutil.copy('tests/data/simple/settings.yaml', tmpdir) + shutil.copytree( + 'tests/data/simple/items', + os.path.join(tmpdir, 'items'), + ) + collection = lesana.Collection.init(tmpdir) + # We start with one item indexed with the term "another" + collection.start_search('another') + mset = collection._enquire.get_mset(0, 10) + self.assertEqual(mset.get_matches_estimated(), 1) + # Then delete it, using the short id + collection.remove_entries(['11189ee4']) + # An now we should have none + self.assertFalse(os.path.exists(os.path.join( + tmpdir, + 'items', + '11189ee47ddf4796b718a483b379f976.yaml' + ))) + collection.start_search('another') + mset = collection._enquire.get_mset(0, 10) + self.assertEqual(mset.get_matches_estimated(), 0) + + def _find_file_in_git_index(self, fname, index): found = False for (path, stage) in index.entries: |