summaryrefslogtreecommitdiff
path: root/test/backupstore/testbackupstore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/backupstore/testbackupstore.cpp')
-rw-r--r--test/backupstore/testbackupstore.cpp1118
1 files changed, 1118 insertions, 0 deletions
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp
index 646e6b45..cc708da0 100644
--- a/test/backupstore/testbackupstore.cpp
+++ b/test/backupstore/testbackupstore.cpp
@@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
+<<<<<<< HEAD
#include "Test.h"
#include "autogen_BackupProtocolClient.h"
#include "SSLLib.h"
@@ -38,6 +39,36 @@
#include "BackupStoreRefCountDatabase.h"
#include "BackupStoreAccounts.h"
#include "HousekeepStoreAccount.h"
+=======
+#include "Archive.h"
+#include "BackupClientCryptoKeys.h"
+#include "BackupClientFileAttributes.h"
+#include "BackupStoreAccountDatabase.h"
+#include "BackupStoreAccounts.h"
+#include "BackupStoreConstants.h"
+#include "BackupStoreDirectory.h"
+#include "BackupStoreException.h"
+#include "BackupStoreInfo.h"
+#include "BackupStoreFilenameClear.h"
+#include "BackupStoreRefCountDatabase.h"
+#include "BackupStoreFile.h"
+#include "BoxPortsAndFiles.h"
+#include "CollectInBufferStream.h"
+#include "FileStream.h"
+#include "HousekeepStoreAccount.h"
+#include "MemBlockStream.h"
+#include "RaidFileController.h"
+#include "RaidFileException.h"
+#include "RaidFileRead.h"
+#include "RaidFileWrite.h"
+#include "SSLLib.h"
+#include "ServerControl.h"
+#include "Socket.h"
+#include "SocketStreamTLS.h"
+#include "TLSContext.h"
+#include "Test.h"
+#include "autogen_BackupProtocol.h"
+>>>>>>> 0.12
#include "MemLeakFindOn.h"
@@ -221,10 +252,13 @@ void CheckEntries(BackupStoreDirectory &rDir, int16_t FlagsMustBeSet, int16_t Fl
int test1(int argc, const char *argv[])
{
+<<<<<<< HEAD
// Initialise the raid file controller
RaidFileController &rcontroller = RaidFileController::GetController();
rcontroller.Initialise("testfiles/raidfile.conf");
+=======
+>>>>>>> 0.12
// test some basics -- encoding and decoding filenames
{
// Make some filenames in various ways
@@ -437,6 +471,7 @@ void test_test_file(int t, IOStream &rStream)
void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID)
{
+<<<<<<< HEAD
printf("Test for del: %llx\n", DirID);
// Command
@@ -444,6 +479,15 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID)
DirID,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ printf("Test for del: %llx\n", (unsigned long long)DirID);
+
+ // Command
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
+ DirID,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream());
@@ -455,7 +499,11 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID)
int dirs = 0;
while((en = i.Next()) != 0)
{
+<<<<<<< HEAD
if(en->GetFlags() & BackupProtocolClientListDirectory::Flags_Dir)
+=======
+ if(en->GetFlags() & BackupProtocolListDirectory::Flags_Dir)
+>>>>>>> 0.12
{
dirs++;
// Recurse
@@ -466,7 +514,11 @@ void test_everything_deleted(BackupProtocolClient &protocol, int64_t DirID)
files++;
}
// Check it's deleted
+<<<<<<< HEAD
TEST_THAT(en->GetFlags() & BackupProtocolClientListDirectory::Flags_Deleted);
+=======
+ TEST_THAT(en->GetFlags() & BackupProtocolListDirectory::Flags_Deleted);
+>>>>>>> 0.12
}
// Check there were the right number of files and directories
@@ -478,7 +530,11 @@ std::vector<uint32_t> ExpectedRefCounts;
void set_refcount(int64_t ObjectID, uint32_t RefCount = 1)
{
+<<<<<<< HEAD
if (ExpectedRefCounts.size() <= ObjectID);
+=======
+ if ((int64_t)ExpectedRefCounts.size() <= ObjectID);
+>>>>>>> 0.12
{
ExpectedRefCounts.resize(ObjectID + 1, 0);
}
@@ -491,7 +547,11 @@ void create_file_in_dir(std::string name, std::string source, int64_t parentId,
BackupStoreFilenameClear name_encoded("file_One");
std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(
source.c_str(), parentId, name_encoded));
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> stored(
+=======
+ std::auto_ptr<BackupProtocolSuccess> stored(
+>>>>>>> 0.12
protocol.QueryStoreFile(
parentId,
0x123456789abcdefLL, /* modification time */
@@ -515,13 +575,22 @@ int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir,
// Create with dummy attributes
int attrS = 0;
MemBlockStream attr(&attrS, sizeof(attrS));
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory(
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory(
+>>>>>>> 0.12
indir,
9837429842987984LL, dirname, attr));
subdirid = dirCreate->GetObjectID();
}
+<<<<<<< HEAD
printf("Create subdirs, depth = %d, dirid = %llx\n", depth, subdirid);
+=======
+ printf("Create subdirs, depth = %d, dirid = %llx\n", depth,
+ (unsigned long long)subdirid);
+>>>>>>> 0.12
TEST_EQUAL(subdirid, rRefCount.GetLastObjectIDUsed());
TEST_EQUAL(1, rRefCount.GetRefCount(subdirid))
@@ -550,11 +619,19 @@ int64_t create_test_data_subdirs(BackupProtocolClient &protocol, int64_t indir,
void check_dir_after_uploads(BackupProtocolClient &protocol, const StreamableMemBlock &Attributes)
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
TEST_THAT(dirreply->GetObjectID() == BackupProtocolClientListDirectory::RootDirectory);
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+ TEST_THAT(dirreply->GetObjectID() == BackupProtocolListDirectory::RootDirectory);
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream());
@@ -575,9 +652,15 @@ void check_dir_after_uploads(BackupProtocolClient &protocol, const StreamableMem
TEST_THAT(en->GetName() == uploads[t].name);
TEST_THAT(en->GetObjectID() == uploads[t].allocated_objid);
TEST_THAT(en->GetModificationTime() == uploads[t].mod_time);
+<<<<<<< HEAD
int correct_flags = BackupProtocolClientListDirectory::Flags_File;
if(uploads[t].should_be_old_version) correct_flags |= BackupProtocolClientListDirectory::Flags_OldVersion;
if(uploads[t].delete_file) correct_flags |= BackupProtocolClientListDirectory::Flags_Deleted;
+=======
+ int correct_flags = BackupProtocolListDirectory::Flags_File;
+ if(uploads[t].should_be_old_version) correct_flags |= BackupProtocolListDirectory::Flags_OldVersion;
+ if(uploads[t].delete_file) correct_flags |= BackupProtocolListDirectory::Flags_Deleted;
+>>>>>>> 0.12
TEST_THAT(en->GetFlags() == correct_flags);
if(t == UPLOAD_ATTRS_EN)
{
@@ -606,10 +689,17 @@ typedef struct
void recursive_count_objects_r(BackupProtocolClient &protocol, int64_t id, recursive_count_objects_results &results)
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory(
id,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
+ id,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream());
@@ -649,9 +739,15 @@ void recursive_count_objects(const char *hostname, int64_t id, recursive_count_o
BackupProtocolClient protocolReadOnly(connReadOnly);
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION));
TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly));
+=======
+ std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION));
+ TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+ std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly));
+>>>>>>> 0.12
}
// Count objects
@@ -758,10 +854,17 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
for(int l = 0; l < 3; ++l)
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream());
@@ -772,10 +875,17 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
// Read the dir from the readonly connection (make sure it gets in the cache)
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
@@ -787,7 +897,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
BackupStoreFilenameClear store1name("testfiles/file1");
{
FileStream out("testfiles/file1_upload1", O_WRONLY | O_CREAT | O_EXCL);
+<<<<<<< HEAD
std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolClientListDirectory::RootDirectory, store1name));
+=======
+ std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolListDirectory::RootDirectory, store1name));
+>>>>>>> 0.12
encoded->CopyStreamTo(out);
}
@@ -797,8 +911,13 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
int64_t store1objid = 0;
{
FileStream upload("testfiles/file1_upload1");
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile(
BackupProtocolClientListDirectory::RootDirectory,
+=======
+ std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile(
+ BackupProtocolListDirectory::RootDirectory,
+>>>>>>> 0.12
0x123456789abcdefLL, /* modification time */
0x7362383249872dfLL, /* attr hash */
0, /* diff from ID */
@@ -811,7 +930,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
// And retrieve it
{
// Retrieve as object
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getfile(protocol.QueryGetObject(store1objid));
+=======
+ std::auto_ptr<BackupProtocolSuccess> getfile(protocol.QueryGetObject(store1objid));
+>>>>>>> 0.12
TEST_THAT(getfile->GetObjectID() == store1objid);
// BLOCK
{
@@ -826,7 +949,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
}
// Retrieve as file
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, store1objid));
+=======
+ std::auto_ptr<BackupProtocolSuccess> getobj(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, store1objid));
+>>>>>>> 0.12
TEST_THAT(getobj->GetObjectID() == store1objid);
// BLOCK
{
@@ -852,7 +979,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
// Retrieve the block index, by ID
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByID(store1objid));
+=======
+ std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByID(store1objid));
+>>>>>>> 0.12
TEST_THAT(getblockindex->GetObjectID() == store1objid);
std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream());
// Check against uploaded file
@@ -860,7 +991,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
}
// and again, by name
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolClientListDirectory::RootDirectory, store1name));
+=======
+ std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolListDirectory::RootDirectory, store1name));
+>>>>>>> 0.12
TEST_THAT(getblockindex->GetObjectID() == store1objid);
std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream());
// Check against uploaded file
@@ -870,10 +1005,17 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
// Get the directory again, and see if the entry is in it
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocol.ReceiveStream());
@@ -896,7 +1038,11 @@ void test_server_1(BackupProtocolClient &protocol, BackupProtocolClient &protoco
// Try using GetFile on a directory
{
+<<<<<<< HEAD
TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, BackupProtocolClientListDirectory::RootDirectory)),
+=======
+ TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> getFile(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, BackupProtocolListDirectory::RootDirectory)),
+>>>>>>> 0.12
ConnectionException, Conn_Protocol_UnexpectedReply);
}
}
@@ -919,6 +1065,7 @@ std::auto_ptr<SocketStreamTLS> open_conn(const char *hostname,
return conn;
}
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClient> test_server_login(SocketStreamTLS& rConn)
{
// Make a protocol
@@ -927,11 +1074,28 @@ std::auto_ptr<BackupProtocolClient> test_server_login(SocketStreamTLS& rConn)
// Check the version
std::auto_ptr<BackupProtocolClientVersion> serverVersion(
+=======
+std::auto_ptr<BackupProtocolClient> test_server_login(const char *hostname,
+ TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn)
+{
+ rapConn = open_conn(hostname, rContext);
+
+ // Make a protocol
+ std::auto_ptr<BackupProtocolClient> protocol(new
+ BackupProtocolClient(*rapConn));
+
+ // Check the version
+ std::auto_ptr<BackupProtocolVersion> serverVersion(
+>>>>>>> 0.12
protocol->QueryVersion(BACKUP_STORE_SERVER_VERSION));
TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
// Login
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(
+=======
+ std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(
+>>>>>>> 0.12
protocol->QueryLogin(0x01234567, 0));
return protocol;
@@ -948,6 +1112,7 @@ void run_housekeeping(BackupStoreAccountDatabase::Entry& rAccount)
housekeeping.DoHousekeeping(true /* keep trying forever */);
}
+<<<<<<< HEAD
int test_server(const char *hostname)
{
TLSContext context;
@@ -955,6 +1120,37 @@ int test_server(const char *hostname)
std::auto_ptr<BackupProtocolClient> apProtocol(
test_server_login(*conn));
BackupProtocolClient& protocol(*apProtocol);
+=======
+// Run housekeeping (for which we need to disconnect ourselves) and check
+// that it doesn't change the numbers of files.
+//
+// Also check that bbstoreaccounts doesn't change anything
+
+void run_housekeeping_and_check_account(const char *hostname,
+ TLSContext& rContext, std::auto_ptr<SocketStreamTLS>& rapConn,
+ std::auto_ptr<BackupProtocolClient>& rapProtocol)
+{
+ rapProtocol->QueryFinished();
+ std::auto_ptr<BackupStoreAccountDatabase> apAccounts(
+ BackupStoreAccountDatabase::Read("testfiles/accounts.txt"));
+ BackupStoreAccountDatabase::Entry account =
+ apAccounts->GetEntry(0x1234567);
+ run_housekeeping(account);
+
+ TEST_THAT(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf check 01234567 fix") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ rapProtocol = test_server_login(hostname, rContext, rapConn);
+}
+
+int test_server(const char *hostname)
+{
+ TLSContext context;
+ std::auto_ptr<SocketStreamTLS> conn;
+ std::auto_ptr<BackupProtocolClient> apProtocol =
+ test_server_login(hostname, context, conn);
+>>>>>>> 0.12
// Make some test attributes
#define ATTR1_SIZE 245
@@ -975,7 +1171,11 @@ int test_server(const char *hostname)
// Get it logging
FILE *protocolLog = ::fopen("testfiles/protocol.log", "w");
TEST_THAT(protocolLog != 0);
+<<<<<<< HEAD
protocol.SetLogToFile(protocolLog);
+=======
+ apProtocol->SetLogToFile(protocolLog);
+>>>>>>> 0.12
#ifndef WIN32
// Check that we can't open a new connection which requests write permissions
@@ -984,16 +1184,26 @@ int test_server(const char *hostname)
conn.Open(context, Socket::TypeINET, hostname,
BOX_PORT_BBSTORED_TEST);
BackupProtocolClient protocol(conn);
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));
TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)),
+=======
+ std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));
+ TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+ TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)),
+>>>>>>> 0.12
ConnectionException, Conn_Protocol_UnexpectedReply);
protocol.QueryFinished();
}
#endif
// Set the client store marker
+<<<<<<< HEAD
protocol.QuerySetClientStoreMarker(0x8732523ab23aLL);
+=======
+ apProtocol->QuerySetClientStoreMarker(0x8732523ab23aLL);
+>>>>>>> 0.12
#ifndef WIN32
// Open a new connection which is read only
@@ -1008,18 +1218,51 @@ int test_server(const char *hostname)
protocolReadOnly.SetLogToFile(protocolReadOnlyLog);
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION));
TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
std::auto_ptr<BackupProtocolClientLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolClientLogin::Flags_ReadOnly));
+=======
+ std::auto_ptr<BackupProtocolVersion> serverVersion(protocolReadOnly.QueryVersion(BACKUP_STORE_SERVER_VERSION));
+ TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+ std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocolReadOnly.QueryLogin(0x01234567, BackupProtocolLogin::Flags_ReadOnly));
+>>>>>>> 0.12
// Check client store marker
TEST_THAT(loginConf->GetClientStoreMarker() == 0x8732523ab23aLL);
}
#else // WIN32
+<<<<<<< HEAD
BackupProtocolClient& protocolReadOnly(protocol);
#endif
test_server_1(protocol, protocolReadOnly);
+=======
+ #define protocolReadOnly (*apProtocol)
+#endif
+
+ test_server_1(*apProtocol, protocolReadOnly);
+
+ #define TEST_NUM_FILES(files, old, deleted, dirs) \
+ { \
+ std::auto_ptr<BackupStoreInfo> apInfo = \
+ BackupStoreInfo::Load(0x1234567, \
+ "backup/01234567/", 0, true); \
+ TEST_EQUAL_LINE(files, apInfo->GetNumFiles(), \
+ "num files"); \
+ TEST_EQUAL_LINE(old, apInfo->GetNumOldFiles(), \
+ "old files"); \
+ TEST_EQUAL_LINE(deleted, apInfo->GetNumDeletedFiles(), \
+ "deleted files"); \
+ TEST_EQUAL_LINE(dirs, apInfo->GetNumDirectories(), \
+ "directories"); \
+ }
+
+ TEST_NUM_FILES(1, 0, 0, 1);
+ run_housekeeping_and_check_account(hostname, context,
+ conn, apProtocol);
+ TEST_NUM_FILES(1, 0, 0, 1);
+>>>>>>> 0.12
// sleep to ensure that the timestamp on the file will change
::safe_sleep(1);
@@ -1033,6 +1276,7 @@ int test_server(const char *hostname)
std::string filename("testfiles/test");
filename += uploads[t].fnextra;
int64_t modtime = 0;
+<<<<<<< HEAD
std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolClientListDirectory::RootDirectory, uploads[t].name, &modtime));
TEST_THAT(modtime != 0);
@@ -1042,6 +1286,17 @@ int test_server(const char *hostname)
modtime,
modtime, /* use it for attr hash too */
0, /* diff from ID */
+=======
+
+ std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolListDirectory::RootDirectory, uploads[t].name, &modtime));
+ TEST_THAT(modtime != 0);
+
+ std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
+ BackupProtocolListDirectory::RootDirectory,
+ modtime,
+ modtime, /* use it for attr hash too */
+ 0, /* diff from ID */
+>>>>>>> 0.12
uploads[t].name,
*upload));
uploads[t].allocated_objid = stored->GetObjectID();
@@ -1051,31 +1306,61 @@ int test_server(const char *hostname)
BOX_TRACE("wrote file " << filename << " to server "
"as object " <<
BOX_FORMAT_OBJECTID(stored->GetObjectID()));
+<<<<<<< HEAD
+=======
+ TEST_NUM_FILES(t + 2, 0, 0, 1);
+
+ run_housekeeping_and_check_account(hostname, context,
+ conn, apProtocol);
+ TEST_NUM_FILES(t + 2, 0, 0, 1);
+>>>>>>> 0.12
}
// Add some attributes onto one of them
{
+<<<<<<< HEAD
MemBlockStream attrnew(attr3, sizeof(attr3));
std::auto_ptr<BackupProtocolClientSuccess> set(protocol.QuerySetReplacementFileAttributes(
BackupProtocolClientListDirectory::RootDirectory,
+=======
+ TEST_NUM_FILES(UPLOAD_NUM + 1, 0, 0, 1);
+ MemBlockStream attrnew(attr3, sizeof(attr3));
+ std::auto_ptr<BackupProtocolSuccess> set(apProtocol->QuerySetReplacementFileAttributes(
+ BackupProtocolListDirectory::RootDirectory,
+>>>>>>> 0.12
32498749832475LL,
uploads[UPLOAD_ATTRS_EN].name,
attrnew));
TEST_THAT(set->GetObjectID() == uploads[UPLOAD_ATTRS_EN].allocated_objid);
+<<<<<<< HEAD
+=======
+ TEST_NUM_FILES(UPLOAD_NUM + 1, 0, 0, 1);
+>>>>>>> 0.12
}
// Delete one of them (will implicitly delete an old version)
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> del(protocol.QueryDeleteFile(
BackupProtocolClientListDirectory::RootDirectory,
uploads[UPLOAD_DELETE_EN].name));
TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
}
+=======
+ std::auto_ptr<BackupProtocolSuccess> del(apProtocol->QueryDeleteFile(
+ BackupProtocolListDirectory::RootDirectory,
+ uploads[UPLOAD_DELETE_EN].name));
+ TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
+ TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1);
+ }
+
+>>>>>>> 0.12
// Check that the block index can be obtained by name even though it's been deleted
{
// Fetch the raw object
{
FileStream out("testfiles/downloaddelobj", O_WRONLY | O_CREAT);
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getobj(protocol.QueryGetObject(uploads[UPLOAD_DELETE_EN].allocated_objid));
std::auto_ptr<IOStream> objstream(protocol.ReceiveStream());
objstream->CopyStreamTo(out);
@@ -1085,6 +1370,17 @@ int test_server(const char *hostname)
BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name));
TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream());
+=======
+ std::auto_ptr<BackupProtocolSuccess> getobj(apProtocol->QueryGetObject(uploads[UPLOAD_DELETE_EN].allocated_objid));
+ std::auto_ptr<IOStream> objstream(apProtocol->ReceiveStream());
+ objstream->CopyStreamTo(out);
+ }
+ // query index and test
+ std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName(
+ BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name));
+ TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
+ std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream());
+>>>>>>> 0.12
TEST_THAT(check_block_index("testfiles/downloaddelobj", *blockIndexStream));
}
@@ -1092,9 +1388,15 @@ int test_server(const char *hostname)
for(int t = 0; t < UPLOAD_NUM; ++t)
{
printf("%d\n", t);
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, uploads[t].allocated_objid));
TEST_THAT(getFile->GetObjectID() == uploads[t].allocated_objid);
std::auto_ptr<IOStream> filestream(protocol.ReceiveStream());
+=======
+ std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, uploads[t].allocated_objid));
+ TEST_THAT(getFile->GetObjectID() == uploads[t].allocated_objid);
+ std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream());
+>>>>>>> 0.12
test_test_file(t, *filestream);
}
@@ -1106,7 +1408,11 @@ int test_server(const char *hostname)
check_dir_after_uploads(protocolReadOnly, attrtest);
printf("done.\n\n");
// And on the read/write one
+<<<<<<< HEAD
check_dir_after_uploads(protocol, attrtest);
+=======
+ check_dir_after_uploads(*apProtocol, attrtest);
+>>>>>>> 0.12
}
// sleep to ensure that the timestamp on the file will change
@@ -1128,12 +1434,43 @@ int test_server(const char *hostname)
out.Write(buf, TEST_FILE_FOR_PATCHING_SIZE - TEST_FILE_FOR_PATCHING_PATCH_AT);
::free(buf);
}
+<<<<<<< HEAD
{
// Fetch the block index for this one
std::auto_ptr<BackupProtocolClientSuccess> getblockindex(protocol.QueryGetBlockIndexByName(
BackupProtocolClientListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name));
TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_PATCH_EN].allocated_objid);
std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream());
+=======
+
+ TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1);
+
+ // Run housekeeping (for which we need to disconnect
+ // ourselves) and check that it doesn't change the numbers
+ // of files
+ apProtocol->QueryFinished();
+ std::auto_ptr<BackupStoreAccountDatabase> apAccounts(
+ BackupStoreAccountDatabase::Read("testfiles/accounts.txt"));
+ BackupStoreAccountDatabase::Entry account =
+ apAccounts->GetEntry(0x1234567);
+ run_housekeeping(account);
+
+ // Also check that bbstoreaccounts doesn't change anything
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf check 01234567 fix") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ apProtocol = test_server_login(hostname, context, conn);
+
+ TEST_NUM_FILES(UPLOAD_NUM, 0, 1, 1);
+
+ {
+ // Fetch the block index for this one
+ std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName(
+ BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name));
+ TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_PATCH_EN].allocated_objid);
+ std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream());
+>>>>>>> 0.12
// Do the patching
bool isCompletelyDifferent = false;
@@ -1141,7 +1478,11 @@ int test_server(const char *hostname)
std::auto_ptr<IOStream> patchstream(
BackupStoreFile::EncodeFileDiff(
TEST_FILE_FOR_PATCHING ".mod",
+<<<<<<< HEAD
BackupProtocolClientListDirectory::RootDirectory,
+=======
+ BackupProtocolListDirectory::RootDirectory,
+>>>>>>> 0.12
uploads[UPLOAD_PATCH_EN].name,
uploads[UPLOAD_PATCH_EN].allocated_objid,
*blockIndexStream,
@@ -1160,8 +1501,13 @@ int test_server(const char *hostname)
int64_t patchedID = 0;
{
FileStream uploadpatch(TEST_FILE_FOR_PATCHING ".patch");
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile(
BackupProtocolClientListDirectory::RootDirectory,
+=======
+ std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
+ BackupProtocolListDirectory::RootDirectory,
+>>>>>>> 0.12
modtime,
modtime, /* use it for attr hash too */
uploads[UPLOAD_PATCH_EN].allocated_objid, /* diff from ID */
@@ -1175,12 +1521,23 @@ int test_server(const char *hostname)
set_refcount(patchedID, 1);
// Then download it to check it's OK
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> getFile(protocol.QueryGetFile(BackupProtocolClientListDirectory::RootDirectory, patchedID));
TEST_THAT(getFile->GetObjectID() == patchedID);
std::auto_ptr<IOStream> filestream(protocol.ReceiveStream());
BackupStoreFile::DecodeFile(*filestream, TEST_FILE_FOR_PATCHING ".downloaded", IOStream::TimeOutInfinite);
// Check it's the same
TEST_THAT(check_files_same(TEST_FILE_FOR_PATCHING ".downloaded", TEST_FILE_FOR_PATCHING ".mod"));
+=======
+ std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, patchedID));
+ TEST_THAT(getFile->GetObjectID() == patchedID);
+ std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream());
+ BackupStoreFile::DecodeFile(*filestream, TEST_FILE_FOR_PATCHING ".downloaded", IOStream::TimeOutInfinite);
+ // Check it's the same
+ TEST_THAT(check_files_same(TEST_FILE_FOR_PATCHING ".downloaded", TEST_FILE_FOR_PATCHING ".mod"));
+
+ TEST_NUM_FILES(UPLOAD_NUM, 1, 1, 1);
+>>>>>>> 0.12
}
// Create a directory
@@ -1189,11 +1546,21 @@ int test_server(const char *hostname)
{
// Attributes
MemBlockStream attr(attr1, sizeof(attr1));
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory(
BackupProtocolClientListDirectory::RootDirectory,
9837429842987984LL, dirname, attr));
subdirid = dirCreate->GetObjectID();
TEST_THAT(subdirid == maxID + 1);
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirCreate(apProtocol->QueryCreateDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ 9837429842987984LL, dirname, attr));
+ subdirid = dirCreate->GetObjectID();
+ TEST_THAT(subdirid == maxID + 1);
+
+ TEST_NUM_FILES(UPLOAD_NUM, 1, 1, 2);
+>>>>>>> 0.12
}
set_refcount(subdirid, 1);
@@ -1205,7 +1572,11 @@ int test_server(const char *hostname)
int64_t modtime;
std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), subdirid, uploads[0].name, &modtime));
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile(
+=======
+ std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
+>>>>>>> 0.12
subdirid,
modtime,
modtime, /* use for attr hash too */
@@ -1213,6 +1584,11 @@ int test_server(const char *hostname)
uploads[0].name,
*upload));
subdirfileid = stored->GetObjectID();
+<<<<<<< HEAD
+=======
+
+ TEST_NUM_FILES(UPLOAD_NUM + 1, 1, 1, 2);
+>>>>>>> 0.12
}
set_refcount(subdirfileid, 1);
@@ -1221,10 +1597,17 @@ int test_server(const char *hostname)
// Check the directories on the read only connection
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream
+>>>>>>> 0.12
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
dir.ReadFromStream(*dirstream, IOStream::TimeOutInfinite);
@@ -1246,17 +1629,28 @@ int test_server(const char *hostname)
}
// Does it look right?
TEST_THAT(en->GetName() == dirname);
+<<<<<<< HEAD
TEST_THAT(en->GetFlags() == BackupProtocolClientListDirectory::Flags_Dir);
+=======
+ TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_Dir);
+>>>>>>> 0.12
TEST_THAT(en->GetObjectID() == subdirid);
TEST_THAT(en->GetModificationTime() == 0); // dirs don't have modification times.
}
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
subdirid,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ subdirid,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */));
+>>>>>>> 0.12
TEST_THAT(dirreply->GetObjectID() == subdirid);
// Stream
BackupStoreDirectory dir;
@@ -1271,7 +1665,11 @@ int test_server(const char *hostname)
TEST_THAT(en != 0);
// Does it look right?
TEST_THAT(en->GetName() == uploads[0].name);
+<<<<<<< HEAD
TEST_THAT(en->GetFlags() == BackupProtocolClientListDirectory::Flags_File);
+=======
+ TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_File);
+>>>>>>> 0.12
TEST_THAT(en->GetObjectID() == subdirfileid);
TEST_THAT(en->GetModificationTime() != 0);
@@ -1286,10 +1684,17 @@ int test_server(const char *hostname)
// Check that we don't get attributes if we don't ask for them
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
subdirid,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ subdirid,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
@@ -1303,7 +1708,11 @@ int test_server(const char *hostname)
// Change attributes on the directory
{
MemBlockStream attrnew(attr2, sizeof(attr2));
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> changereply(protocol.QueryChangeDirAttributes(
+=======
+ std::auto_ptr<BackupProtocolSuccess> changereply(apProtocol->QueryChangeDirAttributes(
+>>>>>>> 0.12
subdirid,
329483209443598LL,
attrnew));
@@ -1312,10 +1721,17 @@ int test_server(const char *hostname)
// Check the new attributes
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
subdirid,
0, // no flags
BackupProtocolClientListDirectory::Flags_EXCLUDE_EVERYTHING, true /* get attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ subdirid,
+ 0, // no flags
+ BackupProtocolListDirectory::Flags_EXCLUDE_EVERYTHING, true /* get attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
@@ -1336,15 +1752,22 @@ int test_server(const char *hostname)
{
BackupStoreFilenameClear newName("moved-files");
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> rep(protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
BackupProtocolClientListDirectory::RootDirectory,
subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName));
+=======
+ std::auto_ptr<BackupProtocolSuccess> rep(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
+ BackupProtocolListDirectory::RootDirectory,
+ subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName));
+>>>>>>> 0.12
TEST_THAT(rep->GetObjectID() == uploads[UPLOAD_FILE_TO_MOVE].allocated_objid);
}
// Try some dodgy renames
{
BackupStoreFilenameClear newName("moved-files");
+<<<<<<< HEAD
TEST_CHECK_THROWS(protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
BackupProtocolClientListDirectory::RootDirectory,
subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName),
@@ -1352,24 +1775,46 @@ int test_server(const char *hostname)
TEST_CHECK_THROWS(protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
subdirid,
subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName),
+=======
+ TEST_CHECK_THROWS(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
+ BackupProtocolListDirectory::RootDirectory,
+ subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName),
+ ConnectionException, Conn_Protocol_UnexpectedReply);
+ TEST_CHECK_THROWS(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
+ subdirid,
+ subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName),
+>>>>>>> 0.12
ConnectionException, Conn_Protocol_UnexpectedReply);
}
// Rename within a directory
{
BackupStoreFilenameClear newName("moved-files-x");
+<<<<<<< HEAD
protocol.QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
subdirid,
subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName);
+=======
+ apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
+ subdirid,
+ subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName);
+>>>>>>> 0.12
}
// Check it's all gone from the root directory...
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
@@ -1388,10 +1833,17 @@ int test_server(const char *hostname)
BackupStoreFilenameClear lookFor("moved-files-x");
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
subdirid,
BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ subdirid,
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
@@ -1423,14 +1875,22 @@ int test_server(const char *hostname)
BackupStoreFilenameClear nd("sub2");
// Attributes
MemBlockStream attr(attr1, sizeof(attr1));
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirCreate(protocol.QueryCreateDirectory(
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirCreate(apProtocol->QueryCreateDirectory(
+>>>>>>> 0.12
subdirid,
9837429842987984LL, nd, attr));
subsubdirid = dirCreate->GetObjectID();
FileStream upload("testfiles/file1_upload1");
BackupStoreFilenameClear nf("file2");
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> stored(protocol.QueryStoreFile(
+=======
+ std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
+>>>>>>> 0.12
subsubdirid,
0x123456789abcdefLL, /* modification time */
0x7362383249872dfLL, /* attr hash */
@@ -1445,6 +1905,7 @@ int test_server(const char *hostname)
// Query names -- test that invalid stuff returns not found OK
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(3248972347823478927LL, subsubdirid));
TEST_THAT(nameRep->GetNumNameElements() == 0);
}
@@ -1458,16 +1919,39 @@ int test_server(const char *hostname)
}
{
std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL));
+=======
+ std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(3248972347823478927LL, subsubdirid));
+ TEST_THAT(nameRep->GetNumNameElements() == 0);
+ }
+ {
+ std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, 2342378424LL));
+ TEST_THAT(nameRep->GetNumNameElements() == 0);
+ }
+ {
+ std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(38947234789LL, 2342378424LL));
+ TEST_THAT(nameRep->GetNumNameElements() == 0);
+ }
+ {
+ std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL));
+>>>>>>> 0.12
TEST_THAT(nameRep->GetNumNameElements() == 0);
}
// Query names... first, get info for the file
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(subsubfileid, subsubdirid));
std::auto_ptr<IOStream> namestream(protocol.ReceiveStream());
TEST_THAT(nameRep->GetNumNameElements() == 3);
TEST_THAT(nameRep->GetFlags() == BackupProtocolClientListDirectory::Flags_File);
+=======
+ std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(subsubfileid, subsubdirid));
+ std::auto_ptr<IOStream> namestream(apProtocol->ReceiveStream());
+
+ TEST_THAT(nameRep->GetNumNameElements() == 3);
+ TEST_THAT(nameRep->GetFlags() == BackupProtocolListDirectory::Flags_File);
+>>>>>>> 0.12
TEST_THAT(nameRep->GetModificationTime() == 0x123456789abcdefLL);
TEST_THAT(nameRep->GetAttributesHash() == 0x7362383249872dfLL);
static const char *testnames[] = {"file2","sub2","lovely_directory"};
@@ -1481,11 +1965,19 @@ int test_server(const char *hostname)
// Query names... secondly, for the directory
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, subsubdirid));
std::auto_ptr<IOStream> namestream(protocol.ReceiveStream());
TEST_THAT(nameRep->GetNumNameElements() == 2);
TEST_THAT(nameRep->GetFlags() == BackupProtocolClientListDirectory::Flags_Dir);
+=======
+ std::auto_ptr<BackupProtocolObjectName> nameRep(apProtocol->QueryGetObjectName(BackupProtocolGetObjectName::ObjectID_DirectoryOnly, subsubdirid));
+ std::auto_ptr<IOStream> namestream(apProtocol->ReceiveStream());
+
+ TEST_THAT(nameRep->GetNumNameElements() == 2);
+ TEST_THAT(nameRep->GetFlags() == BackupProtocolListDirectory::Flags_Dir);
+>>>>>>> 0.12
static const char *testnames[] = {"sub2","lovely_directory"};
for(int l = 0; l < nameRep->GetNumNameElements(); ++l)
{
@@ -1497,21 +1989,33 @@ int test_server(const char *hostname)
//} skip:
+<<<<<<< HEAD
std::auto_ptr<BackupStoreAccountDatabase> apAccounts(
BackupStoreAccountDatabase::Read(
"testfiles/accounts.txt"));
+=======
+>>>>>>> 0.12
std::auto_ptr<BackupStoreRefCountDatabase> apRefCount(
BackupStoreRefCountDatabase::Load(
apAccounts->GetEntry(0x1234567), true));
// Create some nice recursive directories
+<<<<<<< HEAD
int64_t dirtodelete = create_test_data_subdirs(protocol,
BackupProtocolClientListDirectory::RootDirectory,
+=======
+ int64_t dirtodelete = create_test_data_subdirs(*apProtocol,
+ BackupProtocolListDirectory::RootDirectory,
+>>>>>>> 0.12
"test_delete", 6 /* depth */, *apRefCount);
// And delete them
{
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirdel(protocol.QueryDeleteDirectory(
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirdel(apProtocol->QueryDeleteDirectory(
+>>>>>>> 0.12
dirtodelete));
TEST_THAT(dirdel->GetObjectID() == dirtodelete);
}
@@ -1519,10 +2023,17 @@ int test_server(const char *hostname)
// Get the root dir, checking for deleted items
{
// Command
+<<<<<<< HEAD
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocolReadOnly.QueryListDirectory(
BackupProtocolClientListDirectory::RootDirectory,
BackupProtocolClientListDirectory::Flags_Dir | BackupProtocolClientListDirectory::Flags_Deleted,
BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+=======
+ std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ BackupProtocolListDirectory::Flags_Dir | BackupProtocolListDirectory::Flags_Deleted,
+ BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+>>>>>>> 0.12
// Stream
BackupStoreDirectory dir;
std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
@@ -1549,7 +2060,11 @@ int test_server(const char *hostname)
#ifndef WIN32
protocolReadOnly.QueryFinished();
#endif
+<<<<<<< HEAD
protocol.QueryFinished();
+=======
+ apProtocol->QueryFinished();
+>>>>>>> 0.12
// Close logs
#ifndef WIN32
@@ -1742,6 +2257,10 @@ int test3(int argc, const char *argv[])
TEST_CHECK_THROWS(info->ChangeBlocksInDeletedFiles(1), BackupStoreException, StoreInfoIsReadOnly);
TEST_CHECK_THROWS(info->RemovedDeletedDirectory(2), BackupStoreException, StoreInfoIsReadOnly);
TEST_CHECK_THROWS(info->AddDeletedDirectory(2), BackupStoreException, StoreInfoIsReadOnly);
+<<<<<<< HEAD
+=======
+ TEST_CHECK_THROWS(info->SetAccountName("hello"), BackupStoreException, StoreInfoIsReadOnly);
+>>>>>>> 0.12
}
{
std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::Load(76, "test-info/", 0, false));
@@ -1758,6 +2277,10 @@ int test3(int argc, const char *argv[])
info->AddDeletedDirectory(3);
info->AddDeletedDirectory(4);
info->RemovedDeletedDirectory(3);
+<<<<<<< HEAD
+=======
+ info->SetAccountName("whee");
+>>>>>>> 0.12
TEST_CHECK_THROWS(info->RemovedDeletedDirectory(9), BackupStoreException, StoreInfoDirNotInList);
info->Save();
}
@@ -1768,6 +2291,10 @@ int test3(int argc, const char *argv[])
TEST_THAT(info->GetBlocksInDeletedFiles() == 1);
TEST_THAT(info->GetBlocksSoftLimit() == 3461231233455433LL);
TEST_THAT(info->GetBlocksHardLimit() == 2934852487LL);
+<<<<<<< HEAD
+=======
+ TEST_THAT(info->GetAccountName() == "whee");
+>>>>>>> 0.12
const std::vector<int64_t> &delfiles(info->GetDeletedDirectories());
TEST_THAT(delfiles.size() == 2);
TEST_THAT(delfiles[0] == 2);
@@ -1791,6 +2318,7 @@ int test3(int argc, const char *argv[])
int pid = LaunchServer(cmd.c_str(), "testfiles/bbstored.pid");
TEST_THAT(pid != -1 && pid != 0);
+<<<<<<< HEAD
if(pid > 0)
{
::sleep(1);
@@ -2021,6 +2549,276 @@ int test3(int argc, const char *argv[])
TestRemoteProcessMemLeaks("bbstored.memleaks");
#endif
}
+=======
+ if(pid <= 0)
+ {
+ return 1;
+ }
+
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+
+ // BLOCK
+ {
+ // Open a connection to the server
+ SocketStreamTLS conn;
+ conn.Open(context, Socket::TypeINET, "localhost",
+ BOX_PORT_BBSTORED_TEST);
+
+ // Make a protocol
+ BackupProtocolClient protocol(conn);
+
+ // Check the version
+ std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));
+ TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+
+ // Login
+ TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0)),
+ ConnectionException, Conn_Protocol_UnexpectedReply);
+
+ // Finish the connection
+ protocol.QueryFinished();
+ }
+
+ // Create an account for the test client
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf create 01234567 0 "
+ "10000B 20000B") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ TEST_THAT(TestDirExists("testfiles/0_0/backup/01234567"));
+ TEST_THAT(TestDirExists("testfiles/0_1/backup/01234567"));
+ TEST_THAT(TestDirExists("testfiles/0_2/backup/01234567"));
+ TEST_THAT(TestGetFileSize("testfiles/accounts.txt") > 8);
+ // make sure something is written to it
+
+ std::auto_ptr<BackupStoreAccountDatabase> apAccounts(
+ BackupStoreAccountDatabase::Read("testfiles/accounts.txt"));
+
+ std::auto_ptr<BackupStoreRefCountDatabase> apReferences(
+ BackupStoreRefCountDatabase::Load(
+ apAccounts->GetEntry(0x1234567), true));
+ TEST_EQUAL(BACKUPSTORE_ROOT_DIRECTORY_ID,
+ apReferences->GetLastObjectIDUsed());
+ TEST_EQUAL(1, apReferences->GetRefCount(BACKUPSTORE_ROOT_DIRECTORY_ID))
+ apReferences.reset();
+
+ // Test that login fails on a disabled account
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf enabled 01234567 no") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+ // BLOCK
+ {
+ // Open a connection to the server
+ SocketStreamTLS conn;
+ conn.Open(context, Socket::TypeINET, "localhost",
+ BOX_PORT_BBSTORED_TEST);
+
+ // Make a protocol
+ BackupProtocolClient protocol(conn);
+
+ // Check the version
+ std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));
+ TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+
+ // Login
+ TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed>
+ loginConf(protocol.QueryLogin(0x01234567, 0)),
+ ConnectionException, Conn_Protocol_UnexpectedReply);
+ int type, subType;
+ TEST_EQUAL_LINE(true, protocol.GetLastError(type, subType),
+ "expected a protocol error");
+ TEST_EQUAL_LINE(BackupProtocolError::ErrorType, type,
+ "expected a BackupProtocolError");
+ TEST_EQUAL_LINE(BackupProtocolError::Err_DisabledAccount, subType,
+ "expected an Err_DisabledAccount");
+
+ // Finish the connection
+ protocol.QueryFinished();
+ }
+
+ // Re-enable the account so that subsequent logins should succeed
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf enabled 01234567 yes") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ // Delete the refcount database and log in again,
+ // check that it is recreated automatically but with
+ // no objects in it, to ensure seamless upgrade.
+ TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw"));
+
+ std::auto_ptr<SocketStreamTLS> conn;
+ test_server_login("localhost", context, conn)->QueryFinished();
+
+ BackupStoreAccountDatabase::Entry account =
+ apAccounts->GetEntry(0x1234567);
+ apReferences = BackupStoreRefCountDatabase::Load(account, true);
+ TEST_EQUAL(0, apReferences->GetLastObjectIDUsed());
+
+ TEST_THAT(ServerIsAlive(pid));
+
+ run_housekeeping(account);
+
+ // Check that housekeeping fixed the ref counts
+ TEST_EQUAL(BACKUPSTORE_ROOT_DIRECTORY_ID,
+ apReferences->GetLastObjectIDUsed());
+ TEST_EQUAL(1, apReferences->GetRefCount(BACKUPSTORE_ROOT_DIRECTORY_ID))
+
+ TEST_THAT(ServerIsAlive(pid));
+
+ set_refcount(BACKUPSTORE_ROOT_DIRECTORY_ID, 1);
+
+ TEST_THAT(test_server("localhost") == 0);
+
+ // test that all object reference counts have the
+ // expected values
+ TEST_EQUAL(ExpectedRefCounts.size() - 1,
+ apReferences->GetLastObjectIDUsed());
+ for (unsigned int i = BACKUPSTORE_ROOT_DIRECTORY_ID;
+ i < ExpectedRefCounts.size(); i++)
+ {
+ TEST_EQUAL_LINE(ExpectedRefCounts[i],
+ apReferences->GetRefCount(i),
+ "object " << BOX_FORMAT_OBJECTID(i));
+ }
+
+ // Delete the refcount database again, and let
+ // housekeeping recreate it and fix the ref counts.
+ // This could also happen after upgrade, if a housekeeping
+ // runs before the user logs in.
+ apReferences.reset();
+ TEST_EQUAL(0, ::unlink("testfiles/0_0/backup/01234567/refcount.db.rfw"));
+ run_housekeeping(account);
+ apReferences = BackupStoreRefCountDatabase::Load(account, true);
+
+ TEST_EQUAL(ExpectedRefCounts.size() - 1,
+ apReferences->GetLastObjectIDUsed());
+ for (unsigned int i = BACKUPSTORE_ROOT_DIRECTORY_ID;
+ i < ExpectedRefCounts.size(); i++)
+ {
+ TEST_EQUAL_LINE(ExpectedRefCounts[i],
+ apReferences->GetRefCount(i),
+ "object " << BOX_FORMAT_OBJECTID(i));
+ }
+
+ // Test the deletion of objects by the housekeeping system
+ // First, things as they are now.
+ recursive_count_objects_results before = {0,0,0};
+
+ recursive_count_objects("localhost", BackupProtocolListDirectory::RootDirectory, before);
+
+ TEST_THAT(before.objectsNotDel != 0);
+ TEST_THAT(before.deleted != 0);
+ TEST_THAT(before.old != 0);
+
+ // Kill it
+ TEST_THAT(KillServer(pid));
+ ::sleep(1);
+ TEST_THAT(!ServerIsAlive(pid));
+
+ #ifdef WIN32
+ TEST_THAT(unlink("testfiles/bbstored.pid") == 0);
+ #else
+ TestRemoteProcessMemLeaks("bbstored.memleaks");
+ #endif
+
+ // Set a new limit on the account -- leave the hard limit
+ // high to make sure the target for freeing space is the
+ // soft limit.
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf setlimit 01234567 "
+ "10B 20000B") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ // Start things up
+ pid = LaunchServer(BBSTORED " testfiles/bbstored.conf",
+ "testfiles/bbstored.pid");
+
+ ::sleep(1);
+ TEST_THAT(ServerIsAlive(pid));
+
+ // wait for housekeeping to happen
+ printf("waiting for housekeeping:\n");
+ for(int l = 0; l < 30; ++l)
+ {
+ ::sleep(1);
+ printf(".");
+ fflush(stdout);
+ }
+ printf("\n");
+
+ // Count the objects again
+ recursive_count_objects_results after = {0,0,0};
+ recursive_count_objects("localhost",
+ BackupProtocolListDirectory::RootDirectory,
+ after);
+
+ // If these tests fail then try increasing the timeout above
+ TEST_THAT(after.objectsNotDel == before.objectsNotDel);
+ TEST_THAT(after.deleted == 0);
+ TEST_THAT(after.old == 0);
+
+ // Set a really small hard limit
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf setlimit 01234567 "
+ "10B 20B") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ // Try to upload a file and create a directory, and check an error is generated
+ {
+ // Open a connection to the server
+ SocketStreamTLS conn;
+ conn.Open(context, Socket::TypeINET, "localhost",
+ BOX_PORT_BBSTORED_TEST);
+
+ // Make a protocol
+ BackupProtocolClient protocol(conn);
+
+ // Check the version
+ std::auto_ptr<BackupProtocolVersion> serverVersion(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));
+ TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+
+ // Login
+ std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(protocol.QueryLogin(0x01234567, 0));
+
+ int64_t modtime = 0;
+
+ BackupStoreFilenameClear fnx("exceed-limit");
+ std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("testfiles/test3", BackupProtocolListDirectory::RootDirectory, fnx, &modtime));
+ TEST_THAT(modtime != 0);
+
+ TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile(
+ BackupProtocolListDirectory::RootDirectory,
+ modtime,
+ modtime, /* use it for attr hash too */
+ 0, /* diff from ID */
+ fnx,
+ *upload)),
+ ConnectionException, Conn_Protocol_UnexpectedReply);
+
+ MemBlockStream attr(&modtime, sizeof(modtime));
+ BackupStoreFilenameClear fnxd("exceed-limit-dir");
+ TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory(
+ BackupProtocolListDirectory::RootDirectory,
+ 9837429842987984LL, fnxd, attr)),
+ ConnectionException, Conn_Protocol_UnexpectedReply);
+
+
+ // Finish the connection
+ protocol.QueryFinished();
+ }
+
+ // Kill it again
+ TEST_THAT(KillServer(pid));
+ ::sleep(1);
+ TEST_THAT(!ServerIsAlive(pid));
+
+ #ifdef WIN32
+ TEST_THAT(unlink("testfiles/bbstored.pid") == 0);
+ #else
+ TestRemoteProcessMemLeaks("bbstored.memleaks");
+ #endif
+>>>>>>> 0.12
return 0;
}
@@ -2068,25 +2866,36 @@ int multi_server()
return 0;
}
+<<<<<<< HEAD
#ifdef WIN32
WCHAR* ConvertUtf8ToWideString(const char* pString);
std::string ConvertPathToAbsoluteUnicode(const char *pFileName);
#endif
int test(int argc, const char *argv[])
+=======
+void test_open_files_with_limited_win32_permissions()
+>>>>>>> 0.12
{
#ifdef WIN32
// this had better work, or bbstored will die when combining diffs
char* file = "foo";
+<<<<<<< HEAD
std::string abs = ConvertPathToAbsoluteUnicode(file);
WCHAR* wfile = ConvertUtf8ToWideString(abs.c_str());
+=======
+>>>>>>> 0.12
DWORD accessRights = FILE_READ_ATTRIBUTES |
FILE_LIST_DIRECTORY | FILE_READ_EA | FILE_WRITE_ATTRIBUTES |
FILE_WRITE_DATA | FILE_WRITE_EA /*| FILE_ALL_ACCESS*/;
DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+<<<<<<< HEAD
HANDLE h1 = CreateFileW(wfile, accessRights, shareMode,
+=======
+ HANDLE h1 = CreateFileA(file, accessRights, shareMode,
+>>>>>>> 0.12
NULL, OPEN_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL);
assert(h1 != INVALID_HANDLE_VALUE);
TEST_THAT(h1 != INVALID_HANDLE_VALUE);
@@ -2094,23 +2903,328 @@ int test(int argc, const char *argv[])
accessRights = FILE_READ_ATTRIBUTES |
FILE_LIST_DIRECTORY | FILE_READ_EA;
+<<<<<<< HEAD
HANDLE h2 = CreateFileW(wfile, accessRights, shareMode,
+=======
+ HANDLE h2 = CreateFileA(file, accessRights, shareMode,
+>>>>>>> 0.12
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
assert(h2 != INVALID_HANDLE_VALUE);
TEST_THAT(h2 != INVALID_HANDLE_VALUE);
CloseHandle(h2);
CloseHandle(h1);
+<<<<<<< HEAD
delete [] wfile;
h1 = openfile("foo", O_CREAT | O_RDWR, 0);
TEST_THAT(h1 != INVALID_HANDLE_VALUE);
h2 = openfile("foo", O_RDWR, 0);
+=======
+
+ h1 = openfile(file, O_CREAT | O_RDWR, 0);
+ TEST_THAT(h1 != INVALID_HANDLE_VALUE);
+ h2 = openfile(file, O_RDWR, 0);
+>>>>>>> 0.12
TEST_THAT(h2 != INVALID_HANDLE_VALUE);
CloseHandle(h2);
CloseHandle(h1);
#endif
+<<<<<<< HEAD
+
+=======
+}
+
+void compare_backupstoreinfo_values_to_expected
+(
+ const std::string& test_phase,
+ const info_StreamFormat_1& expected,
+ const BackupStoreInfo& actual,
+ const std::string& expected_account_name,
+ bool expected_account_enabled,
+ const MemBlockStream& extra_data = MemBlockStream(/* empty */)
+)
+{
+ TEST_EQUAL_LINE(ntohl(expected.mAccountID), actual.GetAccountID(),
+ test_phase << " AccountID");
+ #define TEST_INFO_EQUAL(property) \
+ TEST_EQUAL_LINE(box_ntoh64(expected.m ## property), \
+ actual.Get ## property (), test_phase << " " #property)
+ TEST_INFO_EQUAL(ClientStoreMarker);
+ TEST_INFO_EQUAL(LastObjectIDUsed);
+ TEST_INFO_EQUAL(BlocksUsed);
+ TEST_INFO_EQUAL(BlocksInOldFiles);
+ TEST_INFO_EQUAL(BlocksInDeletedFiles);
+ TEST_INFO_EQUAL(BlocksInDirectories);
+ TEST_INFO_EQUAL(BlocksSoftLimit);
+ TEST_INFO_EQUAL(BlocksHardLimit);
+ #undef TEST_INFO_EQUAL
+
+ // These attributes of the v2 structure are not supported by v1,
+ // so they should all be initialised to 0
+ TEST_EQUAL_LINE(0, actual.GetBlocksInCurrentFiles(),
+ test_phase << " BlocksInCurrentFiles");
+ TEST_EQUAL_LINE(0, actual.GetNumOldFiles(),
+ test_phase << " NumOldFiles");
+ TEST_EQUAL_LINE(0, actual.GetNumDeletedFiles(),
+ test_phase << " NumDeletedFiles");
+ TEST_EQUAL_LINE(0, actual.GetNumDirectories(),
+ test_phase << " NumDirectories");
+
+ // These attributes of the old v1 structure are not actually loaded
+ // or used:
+ // TEST_INFO_EQUAL(CurrentMarkNumber);
+ // TEST_INFO_EQUAL(OptionsPresent);
+
+ TEST_EQUAL_LINE(box_ntoh64(expected.mNumberDeletedDirectories),
+ actual.GetDeletedDirectories().size(),
+ test_phase << " number of deleted directories");
+
+ for (size_t i = 0; i < box_ntoh64(expected.mNumberDeletedDirectories) &&
+ i < actual.GetDeletedDirectories().size(); i++)
+ {
+ TEST_EQUAL_LINE(13 + i, actual.GetDeletedDirectories()[i],
+ test_phase << " deleted directory " << (i+1));
+ }
+
+ TEST_EQUAL_LINE(expected_account_name, actual.GetAccountName(),
+ test_phase << " AccountName");
+ TEST_EQUAL_LINE(expected_account_enabled, actual.IsAccountEnabled(),
+ test_phase << " AccountEnabled");
+
+ TEST_EQUAL_LINE(extra_data.GetSize(), actual.GetExtraData().GetSize(),
+ test_phase << " extra data has wrong size");
+ TEST_EQUAL_LINE(0, memcmp(extra_data.GetBuffer(),
+ actual.GetExtraData().GetBuffer(), extra_data.GetSize()),
+ test_phase << " extra data has wrong contents");
+}
+
+int test_read_old_backupstoreinfo_files()
+{
+ // Create an account for the test client
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf create 01234567 0 "
+ "10000B 20000B") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+ std::auto_ptr<BackupStoreInfo> apInfo = BackupStoreInfo::Load(0x1234567,
+ "backup/01234567/", 0, /* ReadOnly */ false);
+ TEST_EQUAL_LINE(true, apInfo->IsAccountEnabled(),
+ "'bbstoreaccounts create' should have set AccountEnabled flag");
+
+ info_StreamFormat_1 info_v1;
+ info_v1.mMagicValue = htonl(INFO_MAGIC_VALUE_1);
+ info_v1.mAccountID = htonl(0x01234567);
+ info_v1.mClientStoreMarker = box_hton64(3);
+ info_v1.mLastObjectIDUsed = box_hton64(4);
+ info_v1.mBlocksUsed = box_hton64(5);
+ info_v1.mBlocksInOldFiles = box_hton64(6);
+ info_v1.mBlocksInDeletedFiles = box_hton64(7);
+ info_v1.mBlocksInDirectories = box_hton64(8);
+ info_v1.mBlocksSoftLimit = box_hton64(9);
+ info_v1.mBlocksHardLimit = box_hton64(10);
+ info_v1.mCurrentMarkNumber = htonl(11);
+ info_v1.mOptionsPresent = htonl(12);
+ info_v1.mNumberDeletedDirectories = box_hton64(2);
+ // Then mNumberDeletedDirectories * int64_t IDs for the deleted directories
+
+ // Generate the filename
+ std::string info_filename("backup/01234567/" INFO_FILENAME);
+ std::auto_ptr<RaidFileWrite> rfw(new RaidFileWrite(0, info_filename));
+ rfw->Open(/* AllowOverwrite = */ true);
+ rfw->Write(&info_v1, sizeof(info_v1));
+ // Write mNumberDeletedDirectories * int64_t IDs for the deleted directories
+ std::auto_ptr<Archive> apArchive(new Archive(*rfw, IOStream::TimeOutInfinite));
+ apArchive->Write((int64_t) 13);
+ apArchive->Write((int64_t) 14);
+ rfw->Commit(/* ConvertToRaidNow */ true);
+ rfw.reset();
+
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0,
+ /* ReadOnly */ false);
+ compare_backupstoreinfo_values_to_expected("loaded from v1", info_v1,
+ *apInfo, "" /* no name by default */,
+ true /* enabled by default */);
+ apInfo->SetAccountName("bonk");
+
+ // Save the info again
+ apInfo->Save(/* allowOverwrite */ true);
+
+ // Check that it was saved in the new Archive format
+ std::auto_ptr<RaidFileRead> rfr(RaidFileRead::Open(0, info_filename, 0));
+ int32_t magic;
+ if(!rfr->ReadFullBuffer(&magic, sizeof(magic), 0))
+ {
+ THROW_FILE_ERROR("Failed to read store info file: "
+ "short read of magic number", info_filename,
+ BackupStoreException, CouldNotLoadStoreInfo);
+ }
+ TEST_EQUAL_LINE(INFO_MAGIC_VALUE_2, ntohl(magic),
+ "format version in newly saved BackupStoreInfo");
+ rfr.reset();
+
+ // load it, and check that all values are loaded properly
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0,
+ /* ReadOnly */ false);
+ compare_backupstoreinfo_values_to_expected("loaded in v1, resaved in v2",
+ info_v1, *apInfo, "bonk", true);
+
+ // Check that the new AccountEnabled flag is saved properly
+ apInfo->SetAccountEnabled(false);
+ apInfo->Save(/* allowOverwrite */ true);
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0,
+ /* ReadOnly */ false);
+ compare_backupstoreinfo_values_to_expected("saved in v2, loaded in v2",
+ info_v1, *apInfo, "bonk", false /* as modified above */);
+ apInfo->SetAccountEnabled(true);
+ apInfo->Save(/* allowOverwrite */ true);
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0,
+ /* ReadOnly */ true);
+ compare_backupstoreinfo_values_to_expected("resaved in v2 with "
+ "account enabled", info_v1, *apInfo, "bonk",
+ true /* as modified above */);
+
+ // Now save the info in v2 format without the AccountEnabled flag
+ // (boxbackup 0.11 format) and check that the flag is set to true
+ // for backwards compatibility
+
+ rfw.reset(new RaidFileWrite(0, info_filename));
+ rfw->Open(/* allowOverwrite */ true);
+ magic = htonl(INFO_MAGIC_VALUE_2);
+ apArchive.reset(new Archive(*rfw, IOStream::TimeOutInfinite));
+ rfw->Write(&magic, sizeof(magic));
+ apArchive->Write(apInfo->GetAccountID());
+ apArchive->Write(std::string("test"));
+ apArchive->Write(apInfo->GetClientStoreMarker());
+ apArchive->Write(apInfo->GetLastObjectIDUsed());
+ apArchive->Write(apInfo->GetBlocksUsed());
+ apArchive->Write(apInfo->GetBlocksInCurrentFiles());
+ apArchive->Write(apInfo->GetBlocksInOldFiles());
+ apArchive->Write(apInfo->GetBlocksInDeletedFiles());
+ apArchive->Write(apInfo->GetBlocksInDirectories());
+ apArchive->Write(apInfo->GetBlocksSoftLimit());
+ apArchive->Write(apInfo->GetBlocksHardLimit());
+ apArchive->Write(apInfo->GetNumFiles());
+ apArchive->Write(apInfo->GetNumOldFiles());
+ apArchive->Write(apInfo->GetNumDeletedFiles());
+ apArchive->Write(apInfo->GetNumDirectories());
+ apArchive->Write((int64_t) apInfo->GetDeletedDirectories().size());
+ apArchive->Write(apInfo->GetDeletedDirectories()[0]);
+ apArchive->Write(apInfo->GetDeletedDirectories()[1]);
+ rfw->Commit(/* ConvertToRaidNow */ true);
+ rfw.reset();
+
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0,
+ /* ReadOnly */ false);
+ compare_backupstoreinfo_values_to_expected("saved in v2 without "
+ "AccountEnabled", info_v1, *apInfo, "test", true);
+ // Default for missing AccountEnabled should be true
+
+ // Rewrite using full length, so that the first 4 bytes of extra data
+ // doesn't get swallowed by "extra data".
+ apInfo->Save(/* allowOverwrite */ true);
+
+ // Append some extra data after the known account values, to simulate a
+ // new addition to the store format. Check that this extra data is loaded
+ // and resaved with the info file. We made the mistake of deleting it in
+ // 0.11, let's not make the same mistake again.
+ CollectInBufferStream info_data;
+ rfr = RaidFileRead::Open(0, info_filename, 0);
+ rfr->CopyStreamTo(info_data);
+ rfr.reset();
+ info_data.SetForReading();
+ rfw.reset(new RaidFileWrite(0, info_filename));
+ rfw->Open(/* allowOverwrite */ true);
+ info_data.CopyStreamTo(*rfw);
+ char extra_string[] = "hello!";
+ MemBlockStream extra_data(extra_string, strlen(extra_string));
+ extra_data.CopyStreamTo(*rfw);
+ rfw->Commit(/* ConvertToRaidNow */ true);
+ rfw.reset();
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0,
+ /* ReadOnly */ false);
+ TEST_EQUAL_LINE(extra_data.GetSize(), apInfo->GetExtraData().GetSize(),
+ "wrong amount of extra data loaded from info file");
+ TEST_EQUAL_LINE(0, memcmp(extra_data.GetBuffer(),
+ apInfo->GetExtraData().GetBuffer(), extra_data.GetSize()),
+ "extra data loaded from info file has wrong contents");
+ // Save the file and load again, check that the extra data is still there
+ apInfo->Save(/* allowOverwrite */ true);
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true);
+ compare_backupstoreinfo_values_to_expected("saved in future format "
+ "with extra_data", info_v1, *apInfo, "test", true, extra_data);
+
+ // Check that the new bbstoreaccounts command sets the flag properly
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf enabled 01234567 no") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true);
+ TEST_EQUAL_LINE(false, apInfo->IsAccountEnabled(),
+ "'bbstoreaccounts disabled no' should have reset AccountEnabled flag");
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf enabled 01234567 yes") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true);
+ TEST_EQUAL_LINE(true, apInfo->IsAccountEnabled(),
+ "'bbstoreaccounts disabled yes' should have set AccountEnabled flag");
+
+ // Check that BackupStoreInfo::CreateForRegeneration saves all the
+ // expected properties, including any extra data for forward
+ // compatibility
+ extra_data.Seek(0, IOStream::SeekType_Absolute);
+ apInfo = BackupStoreInfo::CreateForRegeneration(
+ apInfo->GetAccountID(), "spurtle" /* rAccountName */,
+ "backup/01234567/" /* rRootDir */, 0 /* DiscSet */,
+ apInfo->GetLastObjectIDUsed(),
+ apInfo->GetBlocksUsed(),
+ apInfo->GetBlocksInCurrentFiles(),
+ apInfo->GetBlocksInOldFiles(),
+ apInfo->GetBlocksInDeletedFiles(),
+ apInfo->GetBlocksInDirectories(),
+ apInfo->GetBlocksSoftLimit(),
+ apInfo->GetBlocksHardLimit(),
+ false /* AccountEnabled */,
+ extra_data);
+ // CreateForRegeneration always sets the ClientStoreMarker to 0
+ info_v1.mClientStoreMarker = 0;
+ // CreateForRegeneration does not store any deleted directories
+ info_v1.mNumberDeletedDirectories = 0;
+
+ // check that the store info has the correct values in memory
+ compare_backupstoreinfo_values_to_expected("stored by "
+ "BackupStoreInfo::CreateForRegeneration", info_v1, *apInfo,
+ "spurtle", false /* AccountEnabled */, extra_data);
+ // Save the file and load again, check that the extra data is still there
+ apInfo->Save(/* allowOverwrite */ true);
+ apInfo = BackupStoreInfo::Load(0x1234567, "backup/01234567/", 0, true);
+ compare_backupstoreinfo_values_to_expected("saved by "
+ "BackupStoreInfo::CreateForRegeneration and reloaded", info_v1,
+ *apInfo, "spurtle", false /* AccountEnabled */, extra_data);
+
+ // Delete the account to leave the store in the same state as before
+ apInfo.reset();
+ TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS
+ " -c testfiles/bbstored.conf delete 01234567 yes") == 0);
+ TestRemoteProcessMemLeaks("bbstoreaccounts.memleaks");
+
+ return 0;
+}
+
+int test(int argc, const char *argv[])
+{
+ test_open_files_with_limited_win32_permissions();
+
+ // Initialise the raid file controller
+ RaidFileController &rcontroller = RaidFileController::GetController();
+ rcontroller.Initialise("testfiles/raidfile.conf");
+
+ int ret = test_read_old_backupstoreinfo_files();
+ if (ret != 0)
+ {
+ return ret;
+ }
+
+>>>>>>> 0.12
// SSL library
SSLLib::Initialise();
@@ -2159,7 +3273,11 @@ int test(int argc, const char *argv[])
/* {
int64_t modtime = 0;
std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile("/Users/ben/temp/large.tar",
+<<<<<<< HEAD
BackupProtocolClientListDirectory::RootDirectory, uploads[0].name, &modtime));
+=======
+ BackupProtocolListDirectory::RootDirectory, uploads[0].name, &modtime));
+>>>>>>> 0.12
TEST_THAT(modtime != 0);
FileStream write("testfiles/large.enc", O_WRONLY | O_CREAT);
upload->CopyStreamTo(write);