Skip to content

Commit

Permalink
Merge pull request snabbco#1092 from Igalia/fix-recursive-inotify
Browse files Browse the repository at this point in the history
Make sure recursive inotify drains all nested events before returning
  • Loading branch information
wingo authored Jun 13, 2018
2 parents aa12d57 + 225878d commit 0e6beac
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/lib/ptree/inotify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ function recursive_directory_inventory_events(dir, cancel_op)
return op.choice(unpack(ops))
end
local rx_op = recompute_rx_op()
while true do
local occupancy = 0
local stopping = false
while not (stopping and occupancy == 0) do
local event = rx_op:perform()
if event == nil then
-- Just pass. Seems the two remove notifications have raced
Expand All @@ -166,9 +168,11 @@ function recursive_directory_inventory_events(dir, cancel_op)
warn('unexpected double-add for %s', name)
end
else
occupancy = occupancy + 1
tx:put({kind='creat', name=event.name})
end
elseif event.kind == 'mkdir' then
occupancy = occupancy + 1
tx:put(event)
elseif event.kind == 'remove' then
local name = event.name
Expand All @@ -177,23 +181,32 @@ function recursive_directory_inventory_events(dir, cancel_op)
-- send rmdir.
subdirs[name].cancel:signal()
else
occupancy = occupancy - 1
tx:put({kind='rm', name=name})
end
elseif event.kind == 'rmdir' then
tx:put(event)
occupancy = occupancy - 1
local name = event.name
if name == dir then
break
elseif subdirs[name] then
subdirs[name] = nil
rx_op = recompute_rx_op()
stopping = true
else
tx:put(event)
if subdirs[name] then
subdirs[name] = nil
rx_op = recompute_rx_op()
end
end
elseif event.kind == 'creat' or event.kind == 'rm' then
elseif event.kind == 'creat' then
occupancy = occupancy + 1
tx:put(event)
elseif event.kind == 'rm' then
occupancy = occupancy - 1
tx:put(event)
else
warn('unexpected event kind on %s: %s', event.name, event.kind)
end
end
tx:put({kind='rmdir', name=dir})
tx:put(nil)
end)
return tx
Expand Down

0 comments on commit 0e6beac

Please sign in to comment.