Changeset 2709


Ignore:
Timestamp:
27/08/2010 10:24:44 (18 months ago)
Author:
chris
Message:

Allow setting the account name using bbstoreaccounts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp

    r2695 r2709  
    209209} 
    210210 
     211int SetAccountName(Configuration &rConfig, const std::string &rUsername, 
     212        int32_t ID, const std::string& rNewAccountName) 
     213{ 
     214        // Become the user specified in the config file? 
     215        std::auto_ptr<UnixUser> user; 
     216        if(!rUsername.empty()) 
     217        { 
     218                // Username specified, change... 
     219                user.reset(new UnixUser(rUsername.c_str())); 
     220                user->ChangeProcessUser(true /* temporary */); 
     221                // Change will be undone at the end of this function 
     222        } 
     223 
     224        // Load in the account database  
     225        std::auto_ptr<BackupStoreAccountDatabase> db(BackupStoreAccountDatabase::Read(rConfig.GetKeyValue("AccountDatabase").c_str())); 
     226         
     227        // Already exists? 
     228        if(!db->EntryExists(ID)) 
     229        { 
     230                BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<  
     231                        " does not exist."); 
     232                return 1; 
     233        } 
     234         
     235        // Load it in 
     236        BackupStoreAccounts acc(*db); 
     237        std::string rootDir; 
     238        int discSet; 
     239        acc.GetAccountRoot(ID, rootDir, discSet); 
     240         
     241        // Attempt to lock 
     242        NamedLock writeLock; 
     243        if(!GetWriteLockOnAccount(writeLock, rootDir, discSet)) 
     244        { 
     245                // Failed to get lock 
     246                return 1; 
     247        } 
     248 
     249        // Load the info 
     250        std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(ID, 
     251                rootDir, discSet, false /* Read/Write */)); 
     252 
     253        info->SetAccountName(rNewAccountName); 
     254         
     255        // Save 
     256        info->Save(); 
     257 
     258        BOX_NOTICE("Account " << BOX_FORMAT_ACCOUNT(ID) << 
     259                " name changed to " << rNewAccountName); 
     260 
     261        return 0; 
     262} 
     263 
     264 
    211265int AccountInfo(Configuration &rConfig, int32_t ID) 
    212266{ 
     
    235289        std::cout << FormatUsageLineStart("Account ID", sMachineReadableOutput) << 
    236290                BOX_FORMAT_ACCOUNT(ID) << std::endl; 
     291        std::cout << FormatUsageLineStart("Account Name", sMachineReadableOutput) << 
     292                info->GetAccountName() << std::endl; 
    237293        std::cout << FormatUsageLineStart("Last object ID", sMachineReadableOutput) << 
    238294                BOX_FORMAT_OBJECTID(info->GetLastObjectIDUsed()) << std::endl; 
    239295        std::cout << FormatUsageLineStart("Used", sMachineReadableOutput) << 
    240296                BlockSizeToString(info->GetBlocksUsed(), 
     297                        info->GetBlocksHardLimit(), discSet) << std::endl; 
     298        std::cout << FormatUsageLineStart("Current files", 
     299                        sMachineReadableOutput) << 
     300                BlockSizeToString(info->GetBlocksInCurrentFiles(), 
    241301                        info->GetBlocksHardLimit(), discSet) << std::endl; 
    242302        std::cout << FormatUsageLineStart("Old files", sMachineReadableOutput) << 
     
    257317        std::cout << FormatUsageLineStart("Client store marker", sMachineReadableOutput) << 
    258318                info->GetLastObjectIDUsed() << std::endl; 
     319        std::cout << FormatUsageLineStart("Live Files", sMachineReadableOutput) << 
     320                info->GetNumFiles() << std::endl; 
     321        std::cout << FormatUsageLineStart("Old Files", sMachineReadableOutput) << 
     322                info->GetNumOldFiles() << std::endl; 
     323        std::cout << FormatUsageLineStart("Deleted Files", sMachineReadableOutput) << 
     324                info->GetNumDeletedFiles() << std::endl; 
     325        std::cout << FormatUsageLineStart("Directories", sMachineReadableOutput) << 
     326                info->GetNumDirectories() << std::endl; 
    259327         
    260328        return 0; 
     
    452520"        will be fixed. If the 'quiet' option is provided, less output is\n" 
    453521"        produced.\n" 
     522"  name <account> <new name>\n" 
     523"        Changes the \"name\" of the account to the specified string.\n" 
     524"        The name is purely cosmetic and intended to make it easier to\n" 
     525"        identify your accounts.\n" 
    454526        ); 
    455527        exit(2); 
     
    570642                 
    571643                return SetLimit(*config, username, id, argv[2], argv[3]); 
     644        } 
     645        else if(::strcmp(argv[0], "name") == 0) 
     646        { 
     647                // Change the limits on this account 
     648                if(argc != 3) 
     649                { 
     650                        BOX_ERROR("name command requires a new name."); 
     651                        return 1; 
     652                } 
     653                 
     654                return SetAccountName(*config, username, id, argv[2]); 
    572655        } 
    573656        else if(::strcmp(argv[0], "delete") == 0) 
Note: See TracChangeset for help on using the changeset viewer.