From: Casey Bodley Date: Tue, 6 Aug 2019 14:35:19 +0000 (-0400) Subject: rgw: user rename overwrites new user with --yes-i-really-mean-it X-Git-Tag: v15.1.0~1913^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c7ea6dc6d6838e2b74f19e548e8135e4cbf05770;p=ceph.git rgw: user rename overwrites new user with --yes-i-really-mean-it if a previous rename attempt fails to complete, it can be restarted with --yes-i-really-mean-it to overwrite the 'stub' user created previously Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 591a7d895cea..c18acd52f7e6 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -5073,8 +5073,14 @@ int main(int argc, const char **argv) output_user_info = false; break; case OPT_USER_RENAME: + if (yes_i_really_mean_it) { + user_op.set_overwrite_new_user(true); + } ret = user.rename(user_op, &err_msg); if (ret < 0) { + if (ret == -EEXIST) { + err_msg += ". to overwrite this user, add --yes-i-really-mean-it"; + } cerr << "could not rename user: " << err_msg << std::endl; return -ret; } diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index a43ac58dc004..4d8be2198d5d 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -1969,8 +1969,9 @@ int RGWUser::execute_user_rename(RGWUserAdminOpState& op_state, std::string *err stub_user_info.user_id = uid; RGWObjVersionTracker objv; + const bool exclusive = !op_state.get_overwrite_new_user(); // overwrite if requested - ret = rgw_store_user_info(store, stub_user_info, nullptr, &objv, real_time(), true); + ret = rgw_store_user_info(store, stub_user_info, nullptr, &objv, real_time(), exclusive); if (ret == -EEXIST) { set_err_msg(err_msg, "user name given by --new-uid already exists"); return ret; diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index fe5a7fbd4353..4b0644582f70 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -161,6 +161,7 @@ struct RGWUserAdminOpState { std::string user_email; std::string display_name; rgw_user new_user_id; + bool overwrite_new_user = false; int32_t max_buckets; __u8 suspended; __u8 admin; @@ -265,6 +266,9 @@ struct RGWUserAdminOpState { new_user_id = id; } + void set_overwrite_new_user(bool b) { + overwrite_new_user = b; + } void set_user_email(std::string& email) { /* always lowercase email address */ @@ -456,6 +460,7 @@ struct RGWUserAdminOpState { std::string get_user_email() { return user_email; } std::string get_display_name() { return display_name; } rgw_user& get_new_uid() { return new_user_id; } + bool get_overwrite_new_user() const { return overwrite_new_user; } map& get_temp_url_keys() { return temp_url_keys; } RGWUserInfo& get_user_info() { return info; }