Skip to content

Commit

Permalink
bbstoreaccounts: more refactoring to support non-raidfile backends
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Jan 8, 2018
1 parent 5c95d92 commit 95be9a6
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions bin/bbstoreaccounts/bbstoreaccounts.cpp
Expand Up @@ -161,47 +161,45 @@ int main(int argc, const char *argv[])
":" << errs);
}

// Initialise the raid file controller
RaidFileController &rcontroller(RaidFileController::GetController());
rcontroller.Initialise(config->GetKeyValue("RaidFileConf").c_str());
std::auto_ptr<BackupStoreAccountControl> apStoreControl;
BackupAccountControl* pControl;

// Get the Account ID (in hex without the leading 0x).
int32_t id;
if(argc == 0 || ::sscanf(argv[0], "%x", &id) != 1)
{
BOX_FATAL("All commands require an account ID, in hex without 0x");
return PrintUsage();
// Initialise the raid file controller
RaidFileController &rcontroller(RaidFileController::GetController());
rcontroller.Initialise(config->GetKeyValue("RaidFileConf").c_str());

// Get the Account ID (in hex without the leading 0x).
int32_t id;
if(argc == 0 || ::sscanf(argv[0], "%x", &id) != 1)
{
BOX_FATAL("All commands require an account ID, in hex without 0x");
return PrintUsage();
}
argv++;
argc--;

apStoreControl.reset(new BackupStoreAccountControl(*config, id,
machineReadableOutput));
pControl = apStoreControl.get();
}
argv++;
argc--;

BackupStoreAccountControl control(*config, id, machineReadableOutput);
BackupAccountControl& control(*pControl);

// Now do the command.
try
{
if(command == "create")
{
// which disc?
int32_t discnum;
int32_t softlimit;
int32_t hardlimit;
if(argc < 3
|| ::sscanf(argv[0], "%d", &discnum) != 1)
// Create the account...
{
BOX_ERROR("create requires raid file disc number, "
"soft and hard limits.");
return 1;
int32_t discnum = 0;
int blocksize = apStoreControl->BlockSizeOfDiscSet(discnum);
// Decode limits
int32_t softlimit = pControl->SizeStringToBlocks(argv[1], blocksize);
int32_t hardlimit = pControl->SizeStringToBlocks(argv[2], blocksize);
return apStoreControl->CreateAccount(discnum, softlimit, hardlimit);
}

// Decode limits
int blocksize = control.BlockSizeOfDiscSet(discnum);
softlimit = control.SizeStringToBlocks(argv[1], blocksize);
hardlimit = control.SizeStringToBlocks(argv[2], blocksize);
control.CheckSoftHardLimits(softlimit, hardlimit);

// Create the account...
return control.CreateAccount(discnum, softlimit, hardlimit);
}
else if(command == "info")
{
Expand Down Expand Up @@ -262,7 +260,7 @@ int main(int argc, const char *argv[])
{
askForConfirmation = false;
}
return control.DeleteAccount(askForConfirmation);
return apStoreControl->DeleteAccount(askForConfirmation);
}
else if(command == "check")
{
Expand All @@ -288,11 +286,11 @@ int main(int argc, const char *argv[])
}

// Check the account
return control.CheckAccount(fixErrors, quiet);
return apStoreControl->CheckAccount(fixErrors, quiet);
}
else if(command == "housekeep")
{
return control.HousekeepAccountNow();
return apStoreControl->HousekeepAccountNow();
}
else
{
Expand Down

0 comments on commit 95be9a6

Please sign in to comment.