From b081743902e952cf969ec7898f7b09ccb3bcb155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 25 Jan 2012 15:54:57 +0100 Subject: [PATCH] Bug #1087: Update cache name index after a chown operation (cherry picked from commit def2de2a6838dbbe8dc6c08dcfdeba74944b4068) --- include/PoolSQL.h | 14 ++++++++++++++ src/pool/PoolSQL.cc | 26 ++++++++++++++++++++++++++ src/rm/RequestManagerChown.cc | 8 ++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 86c1fc0a05..86641daaa7 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -82,6 +82,20 @@ public: */ PoolObjectSQL * get(const string& name, int uid, bool lock); + /** + * Updates the cache name index. Must be called when the owner of an object + * is changed + * + * @param old_name Object's name before the change + * @param old_uid Object's owner ID before the change + * @param new_name Object's name after the change + * @param new_uid Object's owner ID after the change + */ + void update_cache_index(string& old_name, + int old_uid, + string& new_name, + int new_uid); + /** * Finds a set objects that satisfies a given condition * @param oids a vector with the oids of the objects. diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index e8f749e8a3..f763dd2b38 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -339,6 +339,32 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void PoolSQL::update_cache_index(string& old_name, + int old_uid, + string& new_name, + int new_uid) +{ + map::iterator index; + + lock(); + + string old_key = key(old_name, old_uid); + string new_key = key(new_name, new_uid); + + index = name_pool.find(old_key); + + if ( index != name_pool.end() ) + { + name_pool.erase(old_key); + name_pool.insert(make_pair(new_key, index->second)); + } + + unlock(); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void PoolSQL::replace() { bool removed = false; diff --git a/src/rm/RequestManagerChown.cc b/src/rm/RequestManagerChown.cc index f458cbbcf1..e1563dfd83 100644 --- a/src/rm/RequestManagerChown.cc +++ b/src/rm/RequestManagerChown.cc @@ -134,11 +134,16 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList, { failure_response(NO_EXISTS,get_error(object_name(auth_object),oid),att); return; - } + } if ( noid != -1 ) { + string obj_name = object->get_name(); + int old_uid = object->get_uid(); + object->set_user(noid,nuname); + + pool->update_cache_index(obj_name, old_uid, obj_name, noid); } if ( ngid != -1 ) @@ -273,4 +278,3 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList, return; } - \ No newline at end of file