diff --git a/mdb/__init__.py b/mdb/__init__.py index 35c2729..226483e 100644 --- a/mdb/__init__.py +++ b/mdb/__init__.py @@ -61,6 +61,15 @@ def updated_file(path): def remove(self, path): del self.db[_id(path)] + def remove_docs(self, songs): + for song in songs: + song["_deleted"] = True + self.db.update(songs) + + def docs_beneath(self, path): + path = path.split(os.path.sep) + return [row.value for row in self.db.view('_view/tree/by-path', startkey=path, endkey=path + [{}])] + def _song_for(self, path): try: return MusicFile(path) except IOError: return None diff --git a/mdb/watch.py b/mdb/watch.py index e8b91b4..8ba061b 100644 --- a/mdb/watch.py +++ b/mdb/watch.py @@ -33,7 +33,9 @@ def process_IN_MOVED_FROM(self, event): if not event.is_dir: self.process_IN_DELETE(self, event) - print "Don't know how to deal with a moved directory yet." + path = os.path.join(event.path, event.name) + print "Removing %s..." % path + self.db.remove_docs(self.db.docs_beneath(path)) def process_default(self, event): if event.is_dir: return