summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFilippo Cucchetto <filippocucchetto@gmail.com>2018-10-21 10:36:17 +0200
committerLiang Qi <liang.qi@qt.io>2018-11-12 13:01:15 +0000
commit104200d688650db02f1447f73a499784115d897d (patch)
tree692ebf030b770ff677ef5db309b20b56803b1d54 /examples
parentac4f075274414aac1b6cf2e8e854f0f21fee0761 (diff)
Fix QFileSystemWatcher::removePath after move operations
Foreword: - During a file or directory move the inotify id for an entity is not changed. - QFileSystemWatcher implementation uses a QMultiHash for mapping an id to its path. Suppose this filesystem hypothetical directory structure - A |--> B and user watches both A and B directories. Suppose that the B directory gets moved by calling "mv B B1". The user receives a directoryChanged event for parent directory A and scan filesystem for changes. During this scan the user notices: - a new directory B1 - a deleted directory B The user simply invoke QFileSystemWatcher::addPath(B1) and QFileSystemWatcher::removePath(B). With the actual implementation the second operation could fail: - The call QFileSystemWatcher::addPath(B1) insert a duplicated records in the QFileSystemWatcher::idToPath multihash ( {0, "A"}, {1, "A/B"} {1, "A/B1"} - The call QFileSystemWatcher::removePath(B) fails because - it first retrieves the the id for path B ---> pathToId("A/B") <-- return 1 - Then it calls idToPath.take with the id obtain in the previous step <--- idToPath.take(1) This last operation could take the record {1, "A/B1"} instead of the {1, "A/B"} (because both have the same key) meaning that the next check "x != path" evaluates to true (making the removePath function fail). This patch fixes the problem in the following way: - Use idToPath.equal_range in order to obtain all paths with the given id - Remove the correct record that match (id, path) - Prevent the removal of the inotify watch if another record with the same id is still present in the multihash (like a simple reference counting). Change-Id: I9c8480b2a869d91e500af5c4aded596b9aa53b46 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'examples')
0 files changed, 0 insertions, 0 deletions