Author: axeld Date: 2009-11-27 17:36:52 +0100 (Fri, 27 Nov 2009) New Revision: 34317 Changeset: http://dev.haiku-os.org/changeset/34317/haiku Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Changed the query code again to send B_ENTRY_REMOVED/B_ENTRY_CREATED notifications if an inode in a query result was moved/renamed - this time all the information is correct, though. * While I did not introduce B_ENTRY_MOVED for queries yet, this should make adding it very simple (left as an excercise for the reader ;-)) Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.cpp 2009-11-27 16:06:01 UTC (rev 34316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.cpp 2009-11-27 16:36:52 UTC (rev 34317) @@ -1661,3 +1661,31 @@ } } + +void +Query::LiveUpdateRenameMove(Inode* inode, ino_t oldDirectoryID, + const char* oldName, size_t oldLength, ino_t newDirectoryID, + const char* newName, size_t newLength) +{ + if (fPort < 0 || fExpression == NULL) + return; + + // TODO: check if the attribute is part of the query at all... + + status_t oldStatus = fExpression->Root()->Match(inode, "name", + B_STRING_TYPE, (const uint8*)oldName, oldLength); + status_t newStatus = fExpression->Root()->Match(inode, "name", + B_STRING_TYPE, (const uint8*)newName, newLength); + + if (oldStatus != MATCH_OK || oldStatus != newStatus) + return; + + // The entry stays in the query, notify query listeners about the rename + // or move + + notify_query_entry_removed(fPort, fToken, fVolume->ID(), + oldDirectoryID, oldName, inode->ID()); + + notify_query_entry_created(fPort, fToken, fVolume->ID(), + newDirectoryID, newName, inode->ID()); +} Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.h 2009-11-27 16:06:01 UTC (rev 34316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.h 2009-11-27 16:36:52 UTC (rev 34317) @@ -56,6 +56,10 @@ int32 type, const uint8* oldKey, size_t oldLength, const uint8* newKey, size_t newLength); + void LiveUpdateRenameMove(Inode* inode, + ino_t oldDirectoryID, const char* oldName, + size_t oldLength, ino_t newDirectoryID, + const char* newName, size_t newLength); Expression* GetExpression() const { return fExpression; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp 2009-11-27 16:06:01 UTC (rev 34316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp 2009-11-27 16:36:52 UTC (rev 34317) @@ -535,6 +535,24 @@ } +void +Volume::UpdateLiveQueriesRenameMove(Inode* inode, ino_t oldDirectoryID, + const char* oldName, ino_t newDirectoryID, const char* newName) +{ + MutexLocker _(fQueryLock); + + size_t oldLength = strlen(oldName); + size_t newLength = strlen(newName); + + SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator(); + while (iterator.HasNext()) { + Query* query = iterator.Next(); + query->LiveUpdateRenameMove(inode, oldDirectoryID, oldName, oldLength, + newDirectoryID, newName, newLength); + } +} + + /*! Checks if there is a live query whose results depend on the presence or value of the specified attribute. Don't use it if you already have all the data together to evaluate Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h 2009-11-27 16:06:01 UTC (rev 34316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h 2009-11-27 16:36:52 UTC (rev 34317) @@ -117,6 +117,10 @@ const char* attribute, int32 type, const uint8* oldKey, size_t oldLength, const uint8* newKey, size_t newLength); + void UpdateLiveQueriesRenameMove(Inode* inode, + ino_t oldDirectoryID, const char* oldName, + ino_t newDirectoryID, const char* newName); + bool CheckForLiveQuery(const char* attribute); void AddQuery(Query* query); void RemoveQuery(Query* query); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2009-11-27 16:06:01 UTC (rev 34316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2009-11-27 16:36:52 UTC (rev 34317) @@ -1156,6 +1156,9 @@ inode->WriteLockInTransaction(transaction); + volume->UpdateLiveQueriesRenameMove(inode, oldDirectory->ID(), oldName, + newDirectory->ID(), newName); + // update the name only when they differ bool nameUpdated = false; if (strcmp(oldName, newName)) {