Skip to content

Commit

Permalink
Properly handle directories moved out of the watched dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Dec 19, 2008
1 parent cb2e8f6 commit 4b6f653
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mdb/__init__.py
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion mdb/watch.py
Expand Up @@ -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
Expand Down

0 comments on commit 4b6f653

Please sign in to comment.