From 30295b08911ad1a334f200aa0d32c484c6d20914 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 15 May 2021 15:37:11 +0100 Subject: [PATCH] cmdlistener: Introduce start_modify_game Signed-off-by: Ian Jackson --- daemon/cmdlistener.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index fce4a8ab..705bc347 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -93,6 +93,16 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, cmd_s += ".."; } + #[throws(MgmtError)] + fn start_modify_game(game: &InstanceName) + -> (AccountsGuard, Unauthorised) + { + ( + AccountsGuard::lock(), + Instance::lookup_by_name_unauth(&game)?, + ) + } + let resp = (|| Ok::<_,MgmtError>(match cmd { MC::Noop => Fine, @@ -223,8 +233,7 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, MC::UploadBundle { game, size, hash, kind } => { let (upload, auth) = { - let ag = AccountsGuard::lock(); - let gref = Instance::lookup_by_name_unauth(&game)?; + let (ag, gref) = start_modify_game(&game)?; let bundles = gref.lock_bundles(); let mut igu = gref.lock()?; let (ig, auth) = cs.check_acl(&ag, &mut igu, PCH::Instance, @@ -244,8 +253,7 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, Fine } MC::ListBundles { game } => { - let ag = AccountsGuard::lock(); - let gref = Instance::lookup_by_name_unauth(&game)?; + let (ag, gref) = start_modify_game(&game)?; let mut igu = gref.lock()?; let (ig, _) = cs.check_acl(&ag, &mut igu, PCH::Instance, TP_ACCESS_BUNDLES)?; @@ -294,8 +302,7 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, } MC::AlterGame { game, insns, how } => { - let mut ag = AccountsGuard::lock(); - let gref = Instance::lookup_by_name_unauth(&game)?; + let (mut ag, gref) = start_modify_game(&game)?; let mut g = gref.lock()?; execute_for_game(cs, &mut ag, &mut g, insns, how)? } -- 2.30.2