diff options
author | Reinhard Tartler <siretart@tauware.de> | 2017-06-14 19:53:34 -0400 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2017-06-14 19:55:14 -0400 |
commit | e0c122119afea4c951c0c57144d26a473118c254 (patch) | |
tree | 34a02a56f9b017201dfb721ef678c711351466d6 /lib/backupstore/BackupStoreCheck.cpp | |
parent | e0eb815b67734abd09ff41e2271630d4b2a6d760 (diff) |
Fixup botched merge
Diffstat (limited to 'lib/backupstore/BackupStoreCheck.cpp')
-rw-r--r-- | lib/backupstore/BackupStoreCheck.cpp | 304 |
1 files changed, 0 insertions, 304 deletions
diff --git a/lib/backupstore/BackupStoreCheck.cpp b/lib/backupstore/BackupStoreCheck.cpp index 79a61a77..f2302337 100644 --- a/lib/backupstore/BackupStoreCheck.cpp +++ b/lib/backupstore/BackupStoreCheck.cpp @@ -11,19 +11,6 @@ #include <stdio.h> #include <string.h> -<<<<<<< HEAD -#include <unistd.h> - -#include "BackupStoreCheck.h" -#include "StoreStructure.h" -#include "RaidFileRead.h" -#include "RaidFileWrite.h" -#include "autogen_BackupStoreException.h" -#include "BackupStoreObjectMagic.h" -#include "BackupStoreFile.h" -#include "BackupStoreDirectory.h" -#include "BackupStoreConstants.h" -======= #ifdef HAVE_UNISTD_H # include <unistd.h> @@ -42,7 +29,6 @@ #include "RaidFileWrite.h" #include "StoreStructure.h" #include "Utils.h" ->>>>>>> 0.12 #include "MemLeakFindOn.h" @@ -68,11 +54,6 @@ BackupStoreCheck::BackupStoreCheck(const std::string &rStoreRoot, int DiscSetNum mLostDirNameSerial(0), mLostAndFoundDirectoryID(0), mBlocksUsed(0), -<<<<<<< HEAD - mBlocksInOldFiles(0), - mBlocksInDeletedFiles(0), - mBlocksInDirectories(0) -======= mBlocksInCurrentFiles(0), mBlocksInOldFiles(0), mBlocksInDeletedFiles(0), @@ -81,7 +62,6 @@ BackupStoreCheck::BackupStoreCheck(const std::string &rStoreRoot, int DiscSetNum mNumOldFiles(0), mNumDeletedFiles(0), mNumDirectories(0) ->>>>>>> 0.12 { } @@ -105,51 +85,16 @@ BackupStoreCheck::~BackupStoreCheck() // // Function // Name: BackupStoreCheck::Check() -<<<<<<< HEAD -// Purpose: Perform the check on the given account -======= // Purpose: Perform the check on the given account. You need to // hold a lock on the account before calling this! ->>>>>>> 0.12 // Created: 21/4/04 // // -------------------------------------------------------------------------- void BackupStoreCheck::Check() { -<<<<<<< HEAD - // Lock the account - { - std::string writeLockFilename; - StoreStructure::MakeWriteLockFilename(mStoreRoot, mDiscSetNumber, writeLockFilename); - - bool gotLock = false; - int triesLeft = 8; - do - { - gotLock = mAccountLock.TryAndGetLock(writeLockFilename.c_str(), 0600 /* restrictive file permissions */); - - if(!gotLock) - { - --triesLeft; - ::sleep(1); - } - } while(!gotLock && triesLeft > 0); - - if(!gotLock) - { - // Couldn't lock the account -- just stop now - if(!mQuiet) - { - BOX_ERROR("Failed to lock the account -- did not check.\nTry again later after the client has disconnected.\nAlternatively, forcibly kill the server."); - } - THROW_EXCEPTION(BackupStoreException, CouldNotLockStoreAccount) - } - } -======= std::string writeLockFilename; StoreStructure::MakeWriteLockFilename(mStoreRoot, mDiscSetNumber, writeLockFilename); ASSERT(FileExists(writeLockFilename)); ->>>>>>> 0.12 if(!mQuiet && mFixErrors) { @@ -339,8 +284,6 @@ int64_t BackupStoreCheck::CheckObjectsScanDir(int64_t StartID, int Level, const // Read in all the directories, and recurse downwards { -<<<<<<< HEAD -======= // If any of the directories is missing, create it. RaidFileController &rcontroller(RaidFileController::GetController()); RaidFileDiscSet rdiscSet(rcontroller.GetDiscSet(mDiscSetNumber)); @@ -368,7 +311,6 @@ int64_t BackupStoreCheck::CheckObjectsScanDir(int64_t StartID, int Level, const } } ->>>>>>> 0.12 std::vector<std::string> dirs; RaidFileRead::ReadDirectoryContents(mDiscSetNumber, rDirName, RaidFileRead::DirReadType_DirsOnly, dirs); @@ -391,11 +333,7 @@ int64_t BackupStoreCheck::CheckObjectsScanDir(int64_t StartID, int Level, const } else { -<<<<<<< HEAD - BOX_WARNING("Spurious or invalid directory " << -======= BOX_ERROR("Spurious or invalid directory " << ->>>>>>> 0.12 rDirName << DIRECTORY_SEPARATOR << (*i) << " found, " << (mFixErrors?"deleting":"delete manually")); @@ -412,12 +350,8 @@ int64_t BackupStoreCheck::CheckObjectsScanDir(int64_t StartID, int Level, const // // Function // Name: BackupStoreCheck::CheckObjectsDir(int64_t) -<<<<<<< HEAD -// Purpose: Check all the files within this directory which has the given starting ID. -======= // Purpose: Check all the files within this directory which has // the given starting ID. ->>>>>>> 0.12 // Created: 22/4/04 // // -------------------------------------------------------------------------- @@ -465,15 +399,6 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) // Filename is valid, mark as existing idsPresent[n] = true; } -<<<<<<< HEAD - else - { - // info file in root dir is OK! - if(StartID != 0 || ::strcmp("info", (*i).c_str()) != 0) - { - fileOK = false; - } -======= // No other files should be present in subdirectories else if(StartID != 0) { @@ -487,17 +412,12 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) else { fileOK = false; ->>>>>>> 0.12 } if(!fileOK) { // Unexpected or bad file, delete it -<<<<<<< HEAD - BOX_WARNING("Spurious file " << dirName << -======= BOX_ERROR("Spurious file " << dirName << ->>>>>>> 0.12 DIRECTORY_SEPARATOR << (*i) << " found" << (mFixErrors?", deleting":"")); ++mNumberErrorsFound; @@ -520,11 +440,7 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) if(!CheckAndAddObject(StartID | i, dirName + leaf)) { // File was bad, delete it -<<<<<<< HEAD - BOX_WARNING("Corrupted file " << dirName << -======= BOX_ERROR("Corrupted file " << dirName << ->>>>>>> 0.12 leaf << " found" << (mFixErrors?", deleting":"")); ++mNumberErrorsFound; @@ -542,15 +458,6 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) // -------------------------------------------------------------------------- // // Function -<<<<<<< HEAD -// Name: BackupStoreCheck::CheckAndAddObject(int64_t, const std::string &) -// Purpose: Check a specific object and add it to the list if it's OK -- if -// there are any errors with the reading, return false and it'll be deleted. -// Created: 21/4/04 -// -// -------------------------------------------------------------------------- -bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, const std::string &rFilename) -======= // Name: BackupStoreCheck::CheckAndAddObject(int64_t, // const std::string &) // Purpose: Check a specific object and add it to the list @@ -561,7 +468,6 @@ bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, const std::string &rF // -------------------------------------------------------------------------- bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, const std::string &rFilename) ->>>>>>> 0.12 { // Info on object... bool isFile = true; @@ -571,19 +477,12 @@ bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, try { // Open file -<<<<<<< HEAD - std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(mDiscSetNumber, rFilename)); - size = file->GetDiscUsageInBlocks(); - - // Read in first four bytes -- don't have to worry about retrying if not all bytes read as is RaidFile -======= std::auto_ptr<RaidFileRead> file( RaidFileRead::Open(mDiscSetNumber, rFilename)); size = file->GetDiscUsageInBlocks(); // Read in first four bytes -- don't have to worry about // retrying if not all bytes read as is RaidFile ->>>>>>> 0.12 uint32_t signature; if(file->Read(&signature, sizeof(signature)) != sizeof(signature)) { @@ -614,16 +513,6 @@ bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, return false; break; } -<<<<<<< HEAD - - // Add to usage counts - mBlocksUsed += size; - if(!isFile) - { - mBlocksInDirectories += size; - } -======= ->>>>>>> 0.12 } catch(...) { @@ -636,12 +525,6 @@ bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, { return false; } -<<<<<<< HEAD - - // Add to list of IDs known about - AddID(ObjectID, containerID, size, isFile); - -======= // Add to list of IDs known about AddID(ObjectID, containerID, size, isFile); @@ -693,7 +576,6 @@ bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, } } ->>>>>>> 0.12 // Report success return true; } @@ -703,23 +585,15 @@ bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, // // Function // Name: BackupStoreCheck::CheckFile(int64_t, IOStream &) -<<<<<<< HEAD -// Purpose: Do check on file, return original container ID if OK, or -1 on error -======= // Purpose: Do check on file, return original container ID // if OK, or -1 on error ->>>>>>> 0.12 // Created: 22/4/04 // // -------------------------------------------------------------------------- int64_t BackupStoreCheck::CheckFile(int64_t ObjectID, IOStream &rStream) { -<<<<<<< HEAD - // Check that it's not the root directory ID. Having a file as the root directory would be bad. -======= // Check that it's not the root directory ID. Having a file as // the root directory would be bad. ->>>>>>> 0.12 if(ObjectID == BACKUPSTORE_ROOT_DIRECTORY_ID) { // Get that dodgy thing deleted! @@ -729,12 +603,8 @@ int64_t BackupStoreCheck::CheckFile(int64_t ObjectID, IOStream &rStream) // Check the format of the file, and obtain the container ID int64_t originalContainerID = -1; -<<<<<<< HEAD - if(!BackupStoreFile::VerifyEncodedFileFormat(rStream, 0 /* don't want diffing from ID */, -======= if(!BackupStoreFile::VerifyEncodedFileFormat(rStream, 0 /* don't want diffing from ID */, ->>>>>>> 0.12 &originalContainerID)) { // Didn't verify @@ -749,12 +619,8 @@ int64_t BackupStoreCheck::CheckFile(int64_t ObjectID, IOStream &rStream) // // Function // Name: BackupStoreCheck::CheckDirInitial(int64_t, IOStream &) -<<<<<<< HEAD -// Purpose: Do initial check on directory, return container ID if OK, or -1 on error -======= // Purpose: Do initial check on directory, return container ID // if OK, or -1 on error ->>>>>>> 0.12 // Created: 22/4/04 // // -------------------------------------------------------------------------- @@ -793,16 +659,12 @@ void BackupStoreCheck::CheckDirectories() // This phase will check all the files in the directories, make // a note of all directories which are missing, and do initial fixing. -<<<<<<< HEAD - // Scan all objects -======= // The root directory is not contained inside another directory, so // it has no directory entry to scan, but we have to count it // somewhere, so we'll count it here. mNumDirectories++; // Scan all objects. ->>>>>>> 0.12 for(Info_t::const_iterator i(mInfo.begin()); i != mInfo.end(); ++i) { IDBlock *pblock = i->second; @@ -823,24 +685,6 @@ void BackupStoreCheck::CheckDirectories() } // Flag for modifications -<<<<<<< HEAD - bool isModified = false; - - // Check for validity - if(dir.CheckAndFix()) - { - // Wasn't quite right, and has been modified - BOX_WARNING("Directory ID " << - BOX_FORMAT_OBJECTID(pblock->mID[e]) << - " has bad structure"); - ++mNumberErrorsFound; - isModified = true; - } - - // Go through, and check that everything in that directory exists and is valid - std::vector<int64_t> toDelete; - -======= bool isModified = CheckDirectory(dir); // Check the directory again, now that entries have been removed @@ -871,157 +715,10 @@ void BackupStoreCheck::CheckDirectories() } // Count valid entries ->>>>>>> 0.12 BackupStoreDirectory::Iterator i(dir); BackupStoreDirectory::Entry *en = 0; while((en = i.Next()) != 0) { -<<<<<<< HEAD - // Lookup the item - int32_t iIndex; - IDBlock *piBlock = LookupID(en->GetObjectID(), iIndex); - bool badEntry = false; - if(piBlock != 0) - { - // Found. Get flags - uint8_t iflags = GetFlags(piBlock, iIndex); - - // Is the type the same? - if(((iflags & Flags_IsDir) == Flags_IsDir) - != ((en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) == BackupStoreDirectory::Entry::Flags_Dir)) - { - // Entry is of wrong type - BOX_WARNING("Directory ID " << - BOX_FORMAT_OBJECTID(pblock->mID[e]) << - " references object " << - BOX_FORMAT_OBJECTID(en->GetObjectID()) << - " which has a different type than expected."); - badEntry = true; - } - else - { - // Check that the entry is not already contained. - if(iflags & Flags_IsContained) - { - BOX_WARNING("Directory ID " << - BOX_FORMAT_OBJECTID(pblock->mID[e]) << - " references object " << - BOX_FORMAT_OBJECTID(en->GetObjectID()) << - " which is already contained."); - badEntry = true; - } - else - { - // Not already contained -- mark as contained - SetFlags(piBlock, iIndex, iflags | Flags_IsContained); - - // Check that the container ID of the object is correct - if(piBlock->mContainer[iIndex] != pblock->mID[e]) - { - // Needs fixing... - if(iflags & Flags_IsDir) - { - // Add to will fix later list - BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " has wrong container ID."); - mDirsWithWrongContainerID.push_back(en->GetObjectID()); - } - else - { - // This is OK for files, they might move - BOX_WARNING("File ID " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " has different container ID, probably moved"); - } - - // Fix entry for now - piBlock->mContainer[iIndex] = pblock->mID[e]; - } - } - } - - // Check the object size, if it's OK and a file - if(!badEntry && !((iflags & Flags_IsDir) == Flags_IsDir)) - { - if(en->GetSizeInBlocks() != piBlock->mObjectSizeInBlocks[iIndex]) - { - // Correct - en->SetSizeInBlocks(piBlock->mObjectSizeInBlocks[iIndex]); - // Mark as changed - isModified = true; - // Tell user - BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " has wrong size for object " << BOX_FORMAT_OBJECTID(en->GetObjectID())); - } - } - } - else - { - // Item can't be found. Is it a directory? - if(en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) - { - // Store the directory for later attention - mDirsWhichContainLostDirs[en->GetObjectID()] = pblock->mID[e]; - } - else - { - // Just remove the entry - badEntry = true; - BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " references object " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " which does not exist."); - } - } - - // Is this entry worth keeping? - if(badEntry) - { - toDelete.push_back(en->GetObjectID()); - } - else - { - // Add to sizes? - if(en->GetFlags() & BackupStoreDirectory::Entry::Flags_OldVersion) - { - mBlocksInOldFiles += en->GetSizeInBlocks(); - } - if(en->GetFlags() & BackupStoreDirectory::Entry::Flags_Deleted) - { - mBlocksInDeletedFiles += en->GetSizeInBlocks(); - } - } - } - - if(toDelete.size() > 0) - { - // Delete entries from directory - for(std::vector<int64_t>::const_iterator d(toDelete.begin()); d != toDelete.end(); ++d) - { - dir.DeleteEntry(*d); - } - - // Mark as modified - isModified = true; - - // Check the directory again, now that entries have been removed - dir.CheckAndFix(); - - // Errors found - ++mNumberErrorsFound; - } - - if(isModified && mFixErrors) - { - BOX_WARNING("Fixing directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e])); - - // Save back to disc - RaidFileWrite fixed(mDiscSetNumber, filename); - fixed.Open(true /* allow overwriting */); - dir.WriteToStream(fixed); - // Commit it - fixed.Commit(true /* convert to raid representation now */); - } - } - } - } - -} - -======= int32_t iIndex; IDBlock *piBlock = LookupID(en->GetObjectID(), iIndex); @@ -1254,5 +951,4 @@ bool BackupStoreCheck::CheckDirectoryEntry(BackupStoreDirectory::Entry& rEntry, return !badEntry; } ->>>>>>> 0.12 |