summaryrefslogtreecommitdiff
path: root/lib/backupstore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backupstore')
-rw-r--r--lib/backupstore/BackupClientFileAttributes.cpp2
-rw-r--r--lib/backupstore/BackupStoreCheck.cpp10
-rw-r--r--lib/backupstore/BackupStoreCheck2.cpp2
-rw-r--r--lib/backupstore/BackupStoreFile.cpp2
-rw-r--r--lib/backupstore/BackupStoreRefCountDatabase.cpp17
-rw-r--r--lib/backupstore/BackupStoreRefCountDatabase.h3
-rw-r--r--lib/backupstore/StoreTestUtils.cpp55
-rw-r--r--lib/backupstore/StoreTestUtils.h11
8 files changed, 80 insertions, 22 deletions
diff --git a/lib/backupstore/BackupClientFileAttributes.cpp b/lib/backupstore/BackupClientFileAttributes.cpp
index 37140301..431e5587 100644
--- a/lib/backupstore/BackupClientFileAttributes.cpp
+++ b/lib/backupstore/BackupClientFileAttributes.cpp
@@ -814,7 +814,7 @@ void BackupClientFileAttributes::WriteAttributes(const std::string& Filename,
Filename << "'");
#else
// Make a symlink, first deleting anything in the way
- ::unlink(Filename.c_str());
+ EMU_UNLINK(Filename.c_str());
if(::symlink((char*)(pattr + 1), Filename.c_str()) != 0)
{
BOX_LOG_SYS_ERROR("Failed to symlink '" << Filename <<
diff --git a/lib/backupstore/BackupStoreCheck.cpp b/lib/backupstore/BackupStoreCheck.cpp
index b53ebf6d..37e45b03 100644
--- a/lib/backupstore/BackupStoreCheck.cpp
+++ b/lib/backupstore/BackupStoreCheck.cpp
@@ -174,9 +174,17 @@ void BackupStoreCheck::Check()
try
{
+ // We should be able to load a reference to the old refcount database
+ // (read-only) at the same time that we have a reference to the new one
+ // (temporary) open but not yet committed.
std::auto_ptr<BackupStoreRefCountDatabase> apOldRefs =
BackupStoreRefCountDatabase::Load(account, false);
- mNumberErrorsFound += mapNewRefs->ReportChangesTo(*apOldRefs);
+
+ // If we have created a new lost+found directory (and thus allocated it a nonzero
+ // object ID) then it's not surprising that the previous refcount DB did not have
+ // a reference to this directory, and not an error, so ignore it.
+ mNumberErrorsFound += mapNewRefs->ReportChangesTo(*apOldRefs,
+ mLostAndFoundDirectoryID); // ignore_object_id
}
catch(BoxException &e)
{
diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp
index 13831a09..3775cc4a 100644
--- a/lib/backupstore/BackupStoreCheck2.cpp
+++ b/lib/backupstore/BackupStoreCheck2.cpp
@@ -429,7 +429,7 @@ int64_t BackupStoreCheck::GetLostAndFoundDirID()
if(!mFixErrors)
{
// The result will never be used anyway if errors aren't being fixed
- return 1;
+ return 0;
}
// Load up the root directory
diff --git a/lib/backupstore/BackupStoreFile.cpp b/lib/backupstore/BackupStoreFile.cpp
index 99562685..a3e23204 100644
--- a/lib/backupstore/BackupStoreFile.cpp
+++ b/lib/backupstore/BackupStoreFile.cpp
@@ -677,7 +677,7 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile
}
catch(...)
{
- ::unlink(DecodedFilename);
+ EMU_UNLINK(DecodedFilename);
throw;
}
}
diff --git a/lib/backupstore/BackupStoreRefCountDatabase.cpp b/lib/backupstore/BackupStoreRefCountDatabase.cpp
index b2ea1abd..cba989ed 100644
--- a/lib/backupstore/BackupStoreRefCountDatabase.cpp
+++ b/lib/backupstore/BackupStoreRefCountDatabase.cpp
@@ -68,7 +68,7 @@ void BackupStoreRefCountDatabase::Commit()
std::string Final_Filename = GetFilename(mAccount, false);
#ifdef WIN32
- if(FileExists(Final_Filename) && unlink(Final_Filename.c_str()) != 0)
+ if(FileExists(Final_Filename) && EMU_UNLINK(Final_Filename.c_str()) != 0)
{
THROW_EMU_FILE_ERROR("Failed to delete old permanent refcount "
"database file", mFilename, CommonException,
@@ -106,7 +106,7 @@ void BackupStoreRefCountDatabase::Discard()
mapDatabaseFile.reset();
}
- if(unlink(mFilename.c_str()) != 0)
+ if(EMU_UNLINK(mFilename.c_str()) != 0)
{
THROW_EMU_FILE_ERROR("Failed to delete temporary refcount "
"database file", mFilename, CommonException,
@@ -187,7 +187,7 @@ std::auto_ptr<BackupStoreRefCountDatabase>
{
BOX_WARNING(BOX_FILE_MESSAGE(Filename, "Overwriting existing "
"temporary reference count database"));
- if (unlink(Filename.c_str()) != 0)
+ if(EMU_UNLINK(Filename.c_str()) != 0)
{
THROW_SYS_FILE_ERROR("Failed to delete old temporary "
"reference count database file", Filename,
@@ -347,17 +347,22 @@ bool BackupStoreRefCountDatabase::RemoveReference(int64_t ObjectID)
return (refcount > 0);
}
-int BackupStoreRefCountDatabase::ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs)
+int BackupStoreRefCountDatabase::ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs,
+ int64_t ignore_object_id)
{
int ErrorCount = 0;
int64_t MaxOldObjectId = rOldRefs.GetLastObjectIDUsed();
int64_t MaxNewObjectId = GetLastObjectIDUsed();
for (int64_t ObjectID = BACKUPSTORE_ROOT_DIRECTORY_ID;
- ObjectID < std::max(MaxOldObjectId, MaxNewObjectId);
+ ObjectID <= std::max(MaxOldObjectId, MaxNewObjectId);
ObjectID++)
{
- typedef BackupStoreRefCountDatabase::refcount_t refcount_t;
+ if(ObjectID == ignore_object_id)
+ {
+ continue;
+ }
+
refcount_t OldRefs = (ObjectID <= MaxOldObjectId) ?
rOldRefs.GetRefCount(ObjectID) : 0;
refcount_t NewRefs = (ObjectID <= MaxNewObjectId) ?
diff --git a/lib/backupstore/BackupStoreRefCountDatabase.h b/lib/backupstore/BackupStoreRefCountDatabase.h
index 915653a4..6c16516e 100644
--- a/lib/backupstore/BackupStoreRefCountDatabase.h
+++ b/lib/backupstore/BackupStoreRefCountDatabase.h
@@ -87,7 +87,8 @@ public:
void AddReference(int64_t ObjectID);
// RemoveReference returns false if refcount drops to zero
bool RemoveReference(int64_t ObjectID);
- int ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs);
+ int ReportChangesTo(BackupStoreRefCountDatabase& rOldRefs,
+ int64_t ignore_object_id = 0);
private:
static std::string GetFilename(const BackupStoreAccountDatabase::Entry&
diff --git a/lib/backupstore/StoreTestUtils.cpp b/lib/backupstore/StoreTestUtils.cpp
index 2b773cb1..902552d5 100644
--- a/lib/backupstore/StoreTestUtils.cpp
+++ b/lib/backupstore/StoreTestUtils.cpp
@@ -54,7 +54,7 @@ bool delete_account()
}
std::vector<uint32_t> ExpectedRefCounts;
-int bbstored_pid = 0, bbackupd_pid = 0;
+int bbstored_pid = 0, bbackupd_pid = 0, s3simulator_pid = 0;
void set_refcount(int64_t ObjectID, uint32_t RefCount)
{
@@ -266,11 +266,11 @@ bool check_reference_counts()
return counts_ok;
}
-bool StartServer()
+bool StartServer(const std::string& daemon_args)
{
- bbstored_pid = StartDaemon(bbstored_pid,
- BBSTORED " " + bbstored_args + " testfiles/bbstored.conf",
- "testfiles/bbstored.pid");
+ const std::string& daemon_args_final(daemon_args.size() ? daemon_args : bbstored_args);
+ bbstored_pid = StartDaemon(bbstored_pid, BBSTORED " " + daemon_args_final +
+ " testfiles/bbstored.conf", "testfiles/bbstored.pid");
return bbstored_pid != 0;
}
@@ -282,11 +282,11 @@ bool StopServer(bool wait_for_process)
return result;
}
-bool StartClient(const std::string& bbackupd_conf_file)
+bool StartClient(const std::string& bbackupd_conf_file, const std::string& daemon_args)
{
- bbackupd_pid = StartDaemon(bbackupd_pid,
- BBACKUPD " " + bbackupd_args + " " + bbackupd_conf_file,
- "testfiles/bbackupd.pid");
+ const std::string& daemon_args_final(daemon_args.size() ? daemon_args : bbackupd_args);
+ bbackupd_pid = StartDaemon(bbackupd_pid, BBACKUPD " " + daemon_args_final + " -c " +
+ bbackupd_conf_file, "testfiles/bbackupd.pid");
return bbackupd_pid != 0;
}
@@ -298,3 +298,40 @@ bool StopClient(bool wait_for_process)
return result;
}
+bool StartSimulator()
+{
+ s3simulator_pid = StartDaemon(s3simulator_pid,
+ "../../bin/s3simulator/s3simulator " + bbstored_args +
+ " testfiles/s3simulator.conf", "testfiles/s3simulator.pid");
+ return s3simulator_pid != 0;
+}
+
+bool StopSimulator()
+{
+ bool result = StopDaemon(s3simulator_pid, "testfiles/s3simulator.pid",
+ "s3simulator.memleaks", true);
+ s3simulator_pid = 0;
+ return result;
+}
+
+bool kill_running_daemons()
+{
+ bool success = true;
+
+ if(FileExists("testfiles/bbstored.pid"))
+ {
+ TEST_THAT_OR(KillServer("testfiles/bbstored.pid", true), success = false);
+ }
+
+ if(FileExists("testfiles/bbackupd.pid"))
+ {
+ TEST_THAT_OR(KillServer("testfiles/bbackupd.pid", true), success = false);
+ }
+
+ if(FileExists("testfiles/s3simulator.pid"))
+ {
+ TEST_THAT_OR(KillServer("testfiles/s3simulator.pid", true), success = false);
+ }
+
+ return success;
+}
diff --git a/lib/backupstore/StoreTestUtils.h b/lib/backupstore/StoreTestUtils.h
index b3faebb5..794fbd44 100644
--- a/lib/backupstore/StoreTestUtils.h
+++ b/lib/backupstore/StoreTestUtils.h
@@ -66,17 +66,24 @@ bool run_housekeeping_and_check_account();
bool check_reference_counts();
//! Starts the bbstored test server running, which must not already be running.
-bool StartServer();
+bool StartServer(const std::string& daemon_args = "");
//! Stops the currently running bbstored test server.
bool StopServer(bool wait_for_process = false);
//! Starts the bbackupd client running, which must not already be running.
-bool StartClient(const std::string& bbackupd_conf_file = "testfiles/bbackupd.conf");
+bool StartClient(const std::string& bbackupd_conf_file = "testfiles/bbackupd.conf",
+ const std::string& daemon_args = "");
//! Stops the currently running bbackupd client.
bool StopClient(bool wait_for_process = false);
+bool StartSimulator();
+
+bool StopSimulator();
+
+bool kill_running_daemons();
+
//! Creates the standard test account, for example after delete_account().
bool create_account(int soft, int hard);