diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-02-13 23:29:37 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-02-13 23:29:37 +0000 |
commit | 361c204cbee39fc120896e632cbd2b017c261fb6 (patch) | |
tree | e08b4ec835e58d9ad44a61fb4f0de9510e18c8ca /lib/backupstore | |
parent | ba952ab7cd6fddd1a7754544e4322ceb707e2244 (diff) |
Check that adding a new directory doesn't exceed store limits.
Diffstat (limited to 'lib/backupstore')
-rw-r--r-- | lib/backupstore/BackupStoreContext.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp index 8b754d2a..155abd7f 100644 --- a/lib/backupstore/BackupStoreContext.cpp +++ b/lib/backupstore/BackupStoreContext.cpp @@ -1032,6 +1032,7 @@ int64_t BackupStoreContext::AddDirectory(int64_t InDirectory, const BackupStoreF { THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) } + if(mReadOnly) { THROW_EXCEPTION(BackupStoreException, ContextIsReadOnly) @@ -1065,6 +1066,8 @@ int64_t BackupStoreContext::AddDirectory(int64_t InDirectory, const BackupStoreF // Create an empty directory with the given attributes on disc std::string fn; MakeObjectFilename(id, fn, true /* make sure the directory it's in exists */); + int64_t dirSize; + { BackupStoreDirectory emptyDir(id, InDirectory); // add the atttribues @@ -1075,7 +1078,17 @@ int64_t BackupStoreContext::AddDirectory(int64_t InDirectory, const BackupStoreF dirFile.Open(false /* no overwriting */); emptyDir.WriteToStream(dirFile); // Get disc usage, before it's commited - int64_t dirSize = dirFile.GetDiscUsageInBlocks(); + dirSize = dirFile.GetDiscUsageInBlocks(); + + // Exceeds the hard limit? + int64_t newTotalBlocksUsed = mapStoreInfo->GetBlocksUsed() + + dirSize; + if(newTotalBlocksUsed > mapStoreInfo->GetBlocksHardLimit()) + { + THROW_EXCEPTION(BackupStoreException, AddedFileExceedsStorageLimit) + // The file will be deleted automatically by the RaidFile object + } + // Commit the file dirFile.Commit(BACKUP_STORE_CONVERT_TO_RAID_IMMEDIATELY); |