summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-12-09 22:49:41 +0000
committerChris Wilson <chris+github@qwirx.com>2015-12-09 22:49:41 +0000
commitd4cd52ecebe8d214796df99e5f47117fbda91e04 (patch)
treeb5d04dcc55746a90e5fdccae2f5d4a2cd991d2e6 /lib
parent94abf43c3f1e389c6a606988deabc16522b4f32e (diff)
parent57198ec30c5678c5a5ed26ef6b345d289bb48e50 (diff)
Merge Arnaud Grandville's Windows fixes.
Merge branch 'master' of https://github.com/agrandville/boxbackup into appveyor
Diffstat (limited to 'lib')
-rw-r--r--lib/backupstore/BackupStoreDirectory.cpp9
-rw-r--r--lib/backupstore/BackupStoreDirectory.h5
-rw-r--r--lib/backupstore/BackupStoreFileEncodeStream.h8
-rw-r--r--lib/common/Archive.h59
-rw-r--r--lib/common/BoxConfig-MSVC.h3
-rwxr-xr-xlib/common/makeexception.pl.in67
6 files changed, 49 insertions, 102 deletions
diff --git a/lib/backupstore/BackupStoreDirectory.cpp b/lib/backupstore/BackupStoreDirectory.cpp
index 332eca7a..d158cdd4 100644
--- a/lib/backupstore/BackupStoreDirectory.cpp
+++ b/lib/backupstore/BackupStoreDirectory.cpp
@@ -1,7 +1,7 @@
// --------------------------------------------------------------------------
//
// File
-// Name: BackupStoreDirectory.h
+// Name: BackupStoreDirectory.cpp
// Purpose: Representation of a backup directory
// Created: 2003/08/26
//
@@ -36,11 +36,6 @@ typedef struct
// Then a StreamableMemBlock for attributes
} dir_StreamFormat;
-typedef enum
-{
- Option_DependencyInfoPresent = 1
-} dir_StreamFormatOptions;
-
typedef struct
{
uint64_t mModificationTime;
@@ -172,7 +167,7 @@ void BackupStoreDirectory::ReadFromStream(IOStream &rStream, int Timeout)
int count = ntohl(hdr.mNumEntries);
// Clear existing list
- for(std::vector<Entry*>::iterator i = mEntries.begin();
+ for(std::vector<Entry*>::iterator i = mEntries.begin();
i != mEntries.end(); i++)
{
delete (*i);
diff --git a/lib/backupstore/BackupStoreDirectory.h b/lib/backupstore/BackupStoreDirectory.h
index 5bbb0b35..788a3ad0 100644
--- a/lib/backupstore/BackupStoreDirectory.h
+++ b/lib/backupstore/BackupStoreDirectory.h
@@ -47,6 +47,11 @@ public:
}
#endif
+ typedef enum
+ {
+ Option_DependencyInfoPresent = 1
+ } dir_StreamFormatOptions;
+
BackupStoreDirectory();
BackupStoreDirectory(int64_t ObjectID, int64_t ContainerID);
// Convenience constructor from a stream
diff --git a/lib/backupstore/BackupStoreFileEncodeStream.h b/lib/backupstore/BackupStoreFileEncodeStream.h
index 6db09182..5b9b4a61 100644
--- a/lib/backupstore/BackupStoreFileEncodeStream.h
+++ b/lib/backupstore/BackupStoreFileEncodeStream.h
@@ -90,6 +90,9 @@ public:
int64_t GetBytesToUpload() { return mBytesToUpload; }
int64_t GetTotalBytesSent() { return mTotalBytesSent; }
+ static void CalculateBlockSizes(int64_t DataSize, int64_t &rNumBlocksOut,
+ int32_t &rBlockSizeOut, int32_t &rLastBlockSizeOut);
+
private:
enum
{
@@ -98,15 +101,12 @@ private:
Status_BlockListing = 2,
Status_Finished = 3
};
-
-private:
+
void EncodeCurrentBlock();
- void CalculateBlockSizes(int64_t DataSize, int64_t &rNumBlocksOut, int32_t &rBlockSizeOut, int32_t &rLastBlockSizeOut);
void SkipPreviousBlocksInInstruction();
void SetForInstruction();
void StoreBlockIndexEntry(int64_t WncSizeOrBlkIndex, int32_t ClearSize, uint32_t WeakChecksum, uint8_t *pStrongChecksum);
-private:
Recipe *mpRecipe;
IOStream *mpFile; // source file
CollectInBufferStream mData; // buffer for header and index entries
diff --git a/lib/common/Archive.h b/lib/common/Archive.h
index 76b069a0..2b27b303 100644
--- a/lib/common/Archive.h
+++ b/lib/common/Archive.h
@@ -47,6 +47,9 @@ public:
Write((int) Item);
}
void WriteExact(uint32_t Item) { Write((int)Item); }
+ // TODO FIXME: use of "int" here is dangerous and deprecated. It can lead to
+ // incompatible serialisation on non-32-bit machines. Passing anything other
+ // than one of the specifically supported fixed size types should be forbidden.
void Write(int Item)
{
int32_t privItem = htonl(Item);
@@ -57,6 +60,11 @@ public:
int64_t privItem = box_hton64(Item);
mrStream.Write(&privItem, sizeof(privItem), mTimeout);
}
+ void WriteInt16(uint16_t Item)
+ {
+ uint16_t privItem = htons(Item);
+ mrStream.Write(&privItem, sizeof(privItem), mTimeout);
+ }
void WriteExact(uint64_t Item) { Write(Item); }
void Write(uint64_t Item)
{
@@ -109,6 +117,15 @@ public:
}
rItemOut = ntohl(privItem);
}
+ void ReadFullBuffer(void* Buffer, size_t Size)
+ {
+ if(!mrStream.ReadFullBuffer(Buffer, Size,
+ 0 /* not interested in bytes read if this fails */,
+ mTimeout))
+ {
+ THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead);
+ }
+ }
void ReadIfPresent(int &rItemOut, int ValueIfNotPresent)
{
int32_t privItem;
@@ -132,26 +149,22 @@ public:
void Read(int64_t &rItemOut)
{
int64_t privItem;
- if(!mrStream.ReadFullBuffer(&privItem, sizeof(privItem),
- 0 /* not interested in bytes read if this fails */,
- mTimeout))
- {
- THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead);
- }
+ ReadFullBuffer(&privItem, sizeof(privItem));
rItemOut = box_ntoh64(privItem);
}
void ReadExact(uint64_t &rItemOut) { Read(rItemOut); }
void Read(uint64_t &rItemOut)
{
uint64_t privItem;
- if(!mrStream.ReadFullBuffer(&privItem, sizeof(privItem),
- 0 /* not interested in bytes read if this fails */,
- mTimeout))
- {
- THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead);
- }
+ ReadFullBuffer(&privItem, sizeof(privItem));
rItemOut = box_ntoh64(privItem);
}
+ void ReadInt16(uint16_t &rItemOut)
+ {
+ uint16_t privItem;
+ ReadFullBuffer(&privItem, sizeof(privItem));
+ rItemOut = ntohs(privItem);
+ }
void Read(uint8_t &rItemOut)
{
int privItem;
@@ -160,14 +173,14 @@ public:
}
void ReadIfPresent(std::string &rItemOut, const std::string& ValueIfNotPresent)
{
- Read(rItemOut, &ValueIfNotPresent);
+ ReadString(rItemOut, &ValueIfNotPresent);
}
void Read(std::string &rItemOut)
{
- Read(rItemOut, NULL);
+ ReadString(rItemOut, NULL);
}
private:
- void Read(std::string &rItemOut, const std::string* pValueIfNotPresent)
+ void ReadString(std::string &rItemOut, const std::string* pValueIfNotPresent)
{
int size;
int bytesRead;
@@ -193,13 +206,7 @@ private:
if(size < (int) sizeof(buf))
{
// Fetch rest of pPayload, relying on the Protocol to error on stupidly large sizes for us
- if(!mrStream.ReadFullBuffer(buf, size,
- 0 /* not interested in bytes read if this fails */,
- mTimeout))
- {
- THROW_EXCEPTION(CommonException,
- ArchiveBlockIncompleteRead);
- }
+ ReadFullBuffer(buf, size);
// assign to this string, storing the header and the extra payload
rItemOut.assign(buf, size);
}
@@ -210,13 +217,7 @@ private:
char *ppayload = dataB;
// Fetch rest of pPayload, relying on the Protocol to error on stupidly large sizes for us
- if(!mrStream.ReadFullBuffer(ppayload, size,
- 0 /* not interested in bytes read if this fails */,
- mTimeout))
- {
- THROW_EXCEPTION(CommonException,
- ArchiveBlockIncompleteRead);
- }
+ ReadFullBuffer(ppayload, size);
// assign to this string, storing the header and the extra pPayload
rItemOut.assign(ppayload, size);
}
diff --git a/lib/common/BoxConfig-MSVC.h b/lib/common/BoxConfig-MSVC.h
index eeb25d2e..82ab4997 100644
--- a/lib/common/BoxConfig-MSVC.h
+++ b/lib/common/BoxConfig-MSVC.h
@@ -2,6 +2,9 @@
/* lib/common/BoxConfig.h.in. Generated from configure.ac by autoheader. */
/* Hacked by hand to work for MSVC by Chris Wilson */
+// using std::min/max
+#define NOMINMAX
+
/* Define to major version for BDB_VERSION */
/* #undef BDB_VERSION_MAJOR */
diff --git a/lib/common/makeexception.pl.in b/lib/common/makeexception.pl.in
index e4018180..bddaa94a 100755
--- a/lib/common/makeexception.pl.in
+++ b/lib/common/makeexception.pl.in
@@ -73,12 +73,13 @@ class ${class}Exception : public BoxException
public:
${class}Exception(unsigned int SubType,
const std::string& rMessage = "")
- : mSubType(SubType), mMessage(rMessage)
+ : mSubType(SubType), mMessage(rMessage),
+ mWhat(GetMessage(SubType) + std::string(rMessage.empty() ? "" : ": ") + rMessage)
{
}
${class}Exception(const ${class}Exception &rToCopy)
- : mSubType(rToCopy.mSubType), mMessage(rToCopy.mMessage)
+ : mSubType(rToCopy.mSubType), mMessage(rToCopy.mMessage), mWhat(rToCopy.mWhat)
{
}
@@ -117,6 +118,7 @@ print H <<__E;
private:
unsigned int mSubType;
std::string mMessage;
+ std::string mWhat;
};
#endif // $guardname
@@ -133,51 +135,6 @@ print CPP <<__E;
#include "MemLeakFindOn.h"
-#ifdef EXCEPTION_CODENAMES_EXTENDED
- #ifdef EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION
-static const char *whats[] = {
-__E
-
-my $last_seen = -1;
-for(my $e = 0; $e <= $#exception; $e++)
-{
- if($exception[$e] ne '')
- {
- for(my $s = $last_seen + 1; $s < $e; $s++)
- {
- print CPP "\t\"UNUSED\",\n"
- }
- my $ext = ($exception_desc[$e] ne '')?" ($exception_desc[$e])":'';
- print CPP "\t\"${class} ".$exception[$e].$ext.'"'.(($e==$#exception)?'':',')."\n";
- $last_seen = $e;
- }
-}
-
-print CPP <<__E;
-};
- #else
-static const char *whats[] = {
-__E
-
-$last_seen = -1;
-for(my $e = 0; $e <= $#exception; $e++)
-{
- if($exception[$e] ne '')
- {
- for(my $s = $last_seen + 1; $s < $e; $s++)
- {
- print CPP "\t\"UNUSED\",\n"
- }
- print CPP "\t\"${class} ".$exception[$e].'"'.(($e==$#exception)?'':',')."\n";
- $last_seen = $e;
- }
-}
-
-print CPP <<__E;
-};
- #endif
-#endif
-
unsigned int ${class}Exception::GetType() const throw()
{
return ${class}Exception::ExceptionType;
@@ -190,21 +147,7 @@ unsigned int ${class}Exception::GetSubType() const throw()
const char * ${class}Exception::what() const throw()
{
- std::string what = "${class}";
-
-#ifdef EXCEPTION_CODENAMES_EXTENDED
- if(mSubType < (sizeof(whats) / sizeof(whats[0])))
- {
- what = whats[mSubType];
- }
-#endif
-
- if(mMessage != "")
- {
- what += ": " + mMessage;
- }
-
- return what.c_str();
+ return mWhat.c_str();
}
const char * ${class}Exception::GetMessage(int SubType)