Skip to content

Commit

Permalink
Fix "double delete" in FilePoller.
Browse files Browse the repository at this point in the history
Also, make tests more strict.
  • Loading branch information
riccardomurri committed Jan 16, 2018
1 parent 343700f commit 652b60c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
10 changes: 0 additions & 10 deletions gc3libs/poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,6 @@ def _get_events_dir(self, dirpath):
new_events.append((Url(path), event))
self.watch(path)

# check if some file was deleted
already_watched = set(
path
for path in self._watched
if path.startswith(dirpath)
)
for path in (already_watched - contents - set([dirpath])):
new_events.append((Url(path), events['IN_DELETE']))
self._watched.pop(path)

return new_events

register_poller('file', FilePoller, not inotifyx,
Expand Down
5 changes: 5 additions & 0 deletions gc3libs/tests/test_poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import shutil
import tempfile
from time import sleep

import pytest

Expand Down Expand Up @@ -52,15 +53,19 @@ def setUp(self):

def test_filepoller(self):
poller = plr.FilePoller(self.tmpdir)
assert self.tmpdir in poller._watched

# test create file
fpath = os.path.join(self.tmpdir, 'foo')
write_contents(fpath, 'test')
_check_events(poller, fpath, [['IN_CLOSE_WRITE', 'IN_CREATE']])
assert fpath in poller._watched

# test remove file
os.remove(fpath)
assert not os.path.exists(fpath)
_check_events(poller, fpath, [['IN_DELETE']])
assert fpath not in poller._watched


def test_inotifypoller(self):
Expand Down

0 comments on commit 652b60c

Please sign in to comment.