summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-10-28 01:13:54 +0200
committerReinhard Tartler <siretart@tauware.de>2011-10-28 01:13:54 +0200
commit7b4540ae3c9ac331eed17fdf15a33f64b103cb4d (patch)
treeca47acead4e3676acd942de5f443d7bdc5fdd90c /lib
parent8a937bd354001a190dbe66538aacb353e7c99341 (diff)
Import upstream version 0.11.1~r2837
Diffstat (limited to 'lib')
-rw-r--r--lib/backupclient/BackupClientFileAttributes.cpp7
-rw-r--r--lib/backupclient/BackupClientRestore.cpp29
-rw-r--r--lib/backupclient/BackupClientRestore.h1
-rw-r--r--lib/backupclient/BackupDaemonConfigVerify.cpp2
-rw-r--r--lib/backupclient/BackupStoreFile.cpp10
-rw-r--r--lib/common/BufferedStream.cpp2
-rw-r--r--lib/common/BufferedStream.h2
-rw-r--r--lib/common/BufferedWriteStream.cpp181
-rw-r--r--lib/common/BufferedWriteStream.h44
-rw-r--r--lib/common/Configuration.cpp48
-rw-r--r--lib/common/Configuration.h6
-rw-r--r--lib/common/Logging.h5
-rw-r--r--lib/httpserver/HTTPRequest.h3
-rw-r--r--lib/raidfile/RaidFileWrite.cpp2
-rw-r--r--lib/server/Daemon.cpp4
-rw-r--r--lib/win32/emu.cpp4
16 files changed, 329 insertions, 21 deletions
diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp
index af156a1d..b25ed9c7 100644
--- a/lib/backupclient/BackupClientFileAttributes.cpp
+++ b/lib/backupclient/BackupClientFileAttributes.cpp
@@ -843,9 +843,10 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename,
// Try to apply
if(::utimes(Filename, times) != 0)
{
- BOX_LOG_SYS_ERROR("Failed to change times of "
- "file '" << Filename << "'");
- THROW_EXCEPTION(CommonException, OSFileError)
+ BOX_LOG_SYS_WARNING("Failed to change times of "
+ "file '" << Filename << "' to ctime=" <<
+ BOX_FORMAT_TIMESPEC(times[0]) << ", mtime=" <<
+ BOX_FORMAT_TIMESPEC(times[1]));
}
}
diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp
index b1c5cd0f..fa61bb59 100644
--- a/lib/backupclient/BackupClientRestore.cpp
+++ b/lib/backupclient/BackupClientRestore.cpp
@@ -211,7 +211,8 @@ typedef struct
//
// --------------------------------------------------------------------------
static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
- int64_t DirectoryID, std::string &rLocalDirectoryName,
+ int64_t DirectoryID, const std::string &rRemoteDirectoryName,
+ const std::string &rLocalDirectoryName,
RestoreParams &Params, RestoreResumeInfo &rLevel)
{
// If we're resuming... check that we haven't got a next level to
@@ -223,7 +224,9 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
DIRECTORY_SEPARATOR_ASCHAR +
rLevel.mNextLevelLocalName);
BackupClientRestoreDir(rConnection, rLevel.mNextLevelID,
- localDirname, Params, *rLevel.mpNextLevel);
+ rRemoteDirectoryName + '/' +
+ rLevel.mNextLevelLocalName, localDirname,
+ Params, *rLevel.mpNextLevel);
// Add it to the list of done itmes
rLevel.mRestoredObjects.insert(rLevel.mNextLevelID);
@@ -526,6 +529,11 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
}
}
+ BOX_TRACE("Restoring file: " <<
+ rRemoteDirectoryName + '/' +
+ nm.GetClearFilename() << " (" <<
+ en->GetSizeInBlocks() << " blocks)");
+
// Request it from the store
rConnection.QueryGetFile(DirectoryID,
en->GetObjectID());
@@ -739,9 +747,16 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
nm.GetClearFilename()));
// Recurse
+
+ BOX_TRACE("Entering directory: " <<
+ rRemoteDirectoryName + '/' +
+ nm.GetClearFilename());
+
int result = BackupClientRestoreDir(
rConnection, en->GetObjectID(),
- localDirname, Params, rnextLevel);
+ rRemoteDirectoryName + '/' +
+ nm.GetClearFilename(), localDirname,
+ Params, rnextLevel);
if (result != Restore_Complete)
{
@@ -824,8 +839,8 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
//
// --------------------------------------------------------------------------
int BackupClientRestore(BackupProtocolClient &rConnection,
- int64_t DirectoryID, const char *LocalDirectoryName,
- bool PrintDots, bool RestoreDeleted,
+ int64_t DirectoryID, const char *RemoteDirectoryName,
+ const char *LocalDirectoryName, bool PrintDots, bool RestoreDeleted,
bool UndeleteAfterRestoreDeleted, bool Resume,
bool ContinueAfterErrors)
{
@@ -872,9 +887,9 @@ int BackupClientRestore(BackupProtocolClient &rConnection,
}
// Restore the directory
- std::string localName(LocalDirectoryName);
int result = BackupClientRestoreDir(rConnection, DirectoryID,
- localName, params, params.mResumeInfo);
+ RemoteDirectoryName, LocalDirectoryName, params,
+ params.mResumeInfo);
if (result != Restore_Complete)
{
return result;
diff --git a/lib/backupclient/BackupClientRestore.h b/lib/backupclient/BackupClientRestore.h
index 7e492238..311a15bd 100644
--- a/lib/backupclient/BackupClientRestore.h
+++ b/lib/backupclient/BackupClientRestore.h
@@ -24,6 +24,7 @@ enum
int BackupClientRestore(BackupProtocolClient &rConnection,
int64_t DirectoryID,
+ const char *RemoteDirectoryName,
const char *LocalDirectoryName,
bool PrintDots = false,
bool RestoreDeleted = false,
diff --git a/lib/backupclient/BackupDaemonConfigVerify.cpp b/lib/backupclient/BackupDaemonConfigVerify.cpp
index e70ba865..dfef5b03 100644
--- a/lib/backupclient/BackupDaemonConfigVerify.cpp
+++ b/lib/backupclient/BackupDaemonConfigVerify.cpp
@@ -65,7 +65,7 @@ static const ConfigurationVerify verifyserver[] =
static const ConfigurationVerifyKey verifyrootkeys[] =
{
ConfigurationVerifyKey("AccountNumber",
- ConfigTest_Exists | ConfigTest_IsInt),
+ ConfigTest_Exists | ConfigTest_IsUint32),
ConfigurationVerifyKey("UpdateStoreInterval",
ConfigTest_Exists | ConfigTest_IsInt),
ConfigurationVerifyKey("MinimumFileAge",
diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp
index 27e12bc8..17e145a3 100644
--- a/lib/backupclient/BackupStoreFile.cpp
+++ b/lib/backupclient/BackupStoreFile.cpp
@@ -311,7 +311,15 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile
// ASSERT(drained == 0);
// Write the attributes
- stream->GetAttributes().WriteAttributes(DecodedFilename);
+ try
+ {
+ stream->GetAttributes().WriteAttributes(DecodedFilename);
+ }
+ catch (std::exception& e)
+ {
+ BOX_WARNING("Failed to restore attributes on " <<
+ DecodedFilename << ": " << e.what());
+ }
}
catch(...)
{
diff --git a/lib/common/BufferedStream.cpp b/lib/common/BufferedStream.cpp
index 288e1ed1..b58253f3 100644
--- a/lib/common/BufferedStream.cpp
+++ b/lib/common/BufferedStream.cpp
@@ -2,7 +2,7 @@
//
// File
// Name: BufferedStream.cpp
-// Purpose: Buffering wrapper around IOStreams
+// Purpose: Buffering read-only wrapper around IOStreams
// Created: 2007/01/16
//
// --------------------------------------------------------------------------
diff --git a/lib/common/BufferedStream.h b/lib/common/BufferedStream.h
index 234061c4..079c482a 100644
--- a/lib/common/BufferedStream.h
+++ b/lib/common/BufferedStream.h
@@ -2,7 +2,7 @@
//
// File
// Name: BufferedStream.h
-// Purpose: Buffering wrapper around IOStreams
+// Purpose: Buffering read-only wrapper around IOStreams
// Created: 2007/01/16
//
// --------------------------------------------------------------------------
diff --git a/lib/common/BufferedWriteStream.cpp b/lib/common/BufferedWriteStream.cpp
new file mode 100644
index 00000000..797be00d
--- /dev/null
+++ b/lib/common/BufferedWriteStream.cpp
@@ -0,0 +1,181 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: BufferedWriteStream.cpp
+// Purpose: Buffering write-only wrapper around IOStreams
+// Created: 2010/09/13
+//
+// --------------------------------------------------------------------------
+
+#include "Box.h"
+#include "BufferedWriteStream.h"
+#include "CommonException.h"
+
+#include <string.h>
+
+#include "MemLeakFindOn.h"
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::BufferedWriteStream(const char *, int, int)
+// Purpose: Constructor, set up buffer
+// Created: 2007/01/16
+//
+// --------------------------------------------------------------------------
+BufferedWriteStream::BufferedWriteStream(IOStream& rSink)
+: mrSink(rSink), mBufferPosition(0)
+{ }
+
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::Read(void *, int)
+// Purpose: Reads bytes from the file - throws exception
+// Created: 2007/01/16
+//
+// --------------------------------------------------------------------------
+int BufferedWriteStream::Read(void *pBuffer, int NBytes, int Timeout)
+{
+ THROW_EXCEPTION(CommonException, NotSupported);
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::BytesLeftToRead()
+// Purpose: Returns number of bytes to read (may not be most efficient function ever)
+// Created: 2007/01/16
+//
+// --------------------------------------------------------------------------
+IOStream::pos_type BufferedWriteStream::BytesLeftToRead()
+{
+ THROW_EXCEPTION(CommonException, NotSupported);
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::Write(void *, int)
+// Purpose: Writes bytes to the underlying stream (not supported)
+// Created: 2003/07/31
+//
+// --------------------------------------------------------------------------
+void BufferedWriteStream::Write(const void *pBuffer, int NBytes)
+{
+ int numBytesRemain = NBytes;
+
+ do
+ {
+ int maxWritable = sizeof(mBuffer) - mBufferPosition;
+ int numBytesToWrite = (numBytesRemain < maxWritable) ?
+ numBytesRemain : maxWritable;
+
+ if(numBytesToWrite > 0)
+ {
+ memcpy(mBuffer + mBufferPosition, pBuffer,
+ numBytesToWrite);
+ mBufferPosition += numBytesToWrite;
+ pBuffer = ((const char *)pBuffer) + numBytesToWrite;
+ numBytesRemain -= numBytesToWrite;
+ }
+
+ if(numBytesRemain > 0)
+ {
+ Flush();
+ }
+ }
+ while(numBytesRemain > 0);
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::GetPosition()
+// Purpose: Get position in stream
+// Created: 2003/08/21
+//
+// --------------------------------------------------------------------------
+IOStream::pos_type BufferedWriteStream::GetPosition() const
+{
+ return mrSink.GetPosition() + mBufferPosition;
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::Seek(pos_type, int)
+// Purpose: Seeks within file, as lseek, invalidate buffer
+// Created: 2003/07/31
+//
+// --------------------------------------------------------------------------
+void BufferedWriteStream::Seek(IOStream::pos_type Offset, int SeekType)
+{
+ // Always flush the buffer before seeking
+ Flush();
+
+ mrSink.Seek(Offset, SeekType);
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::Flush();
+// Purpose: Write out current buffer contents and invalidate
+// Created: 2010/09/13
+//
+// --------------------------------------------------------------------------
+void BufferedWriteStream::Flush(int Timeout)
+{
+ if(mBufferPosition > 0)
+ {
+ mrSink.Write(mBuffer, mBufferPosition);
+ }
+
+ mBufferPosition = 0;
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::Close()
+// Purpose: Closes the underlying stream (not needed)
+// Created: 2003/07/31
+//
+// --------------------------------------------------------------------------
+void BufferedWriteStream::Close()
+{
+ Flush();
+ mrSink.Close();
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::StreamDataLeft()
+// Purpose: Any data left to write?
+// Created: 2003/08/02
+//
+// --------------------------------------------------------------------------
+bool BufferedWriteStream::StreamDataLeft()
+{
+ THROW_EXCEPTION(CommonException, NotSupported);
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: BufferedWriteStream::StreamClosed()
+// Purpose: Is the stream closed?
+// Created: 2003/08/02
+//
+// --------------------------------------------------------------------------
+bool BufferedWriteStream::StreamClosed()
+{
+ return mrSink.StreamClosed();
+}
+
diff --git a/lib/common/BufferedWriteStream.h b/lib/common/BufferedWriteStream.h
new file mode 100644
index 00000000..7a1c8c17
--- /dev/null
+++ b/lib/common/BufferedWriteStream.h
@@ -0,0 +1,44 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: BufferedWriteStream.h
+// Purpose: Buffering write-only wrapper around IOStreams
+// Created: 2010/09/13
+//
+// --------------------------------------------------------------------------
+
+#ifndef BUFFEREDWRITESTREAM__H
+#define BUFFEREDWRITESTREAM__H
+
+#include "IOStream.h"
+
+class BufferedWriteStream : public IOStream
+{
+private:
+ IOStream& mrSink;
+ char mBuffer[4096];
+ int mBufferPosition;
+
+public:
+ BufferedWriteStream(IOStream& rSource);
+ virtual ~BufferedWriteStream() { Close(); }
+
+ virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
+ virtual pos_type BytesLeftToRead();
+ virtual void Write(const void *pBuffer, int NBytes);
+ virtual pos_type GetPosition() const;
+ virtual void Seek(IOStream::pos_type Offset, int SeekType);
+ virtual void Flush(int Timeout = IOStream::TimeOutInfinite);
+ virtual void Close();
+
+ virtual bool StreamDataLeft();
+ virtual bool StreamClosed();
+
+private:
+ BufferedWriteStream(const BufferedWriteStream &rToCopy)
+ : mrSink(rToCopy.mrSink) { /* do not call */ }
+};
+
+#endif // BUFFEREDWRITESTREAM__H
+
+
diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp
index 2eb5fbca..f49f3c6e 100644
--- a/lib/common/Configuration.cpp
+++ b/lib/common/Configuration.cpp
@@ -453,7 +453,8 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const
}
else
{
- long value = ::strtol((i->second).c_str(), NULL, 0 /* C style handling */);
+ long value = ::strtol((i->second).c_str(), NULL,
+ 0 /* C style handling */);
if(value == LONG_MAX || value == LONG_MIN)
{
THROW_EXCEPTION(CommonException, ConfigBadIntValue)
@@ -466,6 +467,36 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const
// --------------------------------------------------------------------------
//
// Function
+// Name: Configuration::GetKeyValueUint32(const std::string& rKeyName)
+// Purpose: Gets a key value as a 32-bit unsigned integer
+// Created: 2003/07/23
+//
+// --------------------------------------------------------------------------
+uint32_t Configuration::GetKeyValueUint32(const std::string& rKeyName) const
+{
+ std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName));
+
+ if(i == mKeys.end())
+ {
+ THROW_EXCEPTION(CommonException, ConfigNoKey)
+ }
+ else
+ {
+ errno = 0;
+ long value = ::strtoul((i->second).c_str(), NULL,
+ 0 /* C style handling */);
+ if(errno != 0)
+ {
+ THROW_EXCEPTION(CommonException, ConfigBadIntValue)
+ }
+ return (int)value;
+ }
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Function
// Name: Configuration::GetKeyValueBool(const std::string&)
// Purpose: Gets a key value as a boolean
// Created: 17/2/04
@@ -680,6 +711,21 @@ bool Configuration::Verify(const ConfigurationVerify &rVerify,
rErrorMsg += rLevel + mName + "." + pvkey->Name() + " (key) is not a valid integer.\n";
}
}
+
+ // Check it's a number?
+ if(pvkey->Flags() & ConfigTest_IsUint32)
+ {
+ // Test it...
+ char *end;
+ errno = 0;
+ uint32_t r = ::strtoul(val, &end, 0);
+ if(errno != 0 || end != (val + rval.size()))
+ {
+ // not a good value
+ ok = false;
+ rErrorMsg += rLevel + mName + "." + pvkey->Name() + " (key) is not a valid unsigned 32-bit integer.\n";
+ }
+ }
// Check it's a bool?
if((pvkey->Flags() & ConfigTest_IsBool) == ConfigTest_IsBool)
diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h
index 2babd753..4828b315 100644
--- a/lib/common/Configuration.h
+++ b/lib/common/Configuration.h
@@ -22,8 +22,9 @@ enum
ConfigTest_LastEntry = 1,
ConfigTest_Exists = 2,
ConfigTest_IsInt = 4,
- ConfigTest_MultiValueAllowed = 8,
- ConfigTest_IsBool = 16
+ ConfigTest_IsUint32 = 8,
+ ConfigTest_MultiValueAllowed = 16,
+ ConfigTest_IsBool = 32
};
class ConfigurationVerifyKey
@@ -112,6 +113,7 @@ public:
bool KeyExists(const std::string& rKeyName) const;
const std::string &GetKeyValue(const std::string& rKeyName) const;
int GetKeyValueInt(const std::string& rKeyName) const;
+ uint32_t GetKeyValueUint32(const std::string& rKeyName) const;
bool GetKeyValueBool(const std::string& rKeyName) const;
std::vector<std::string> GetKeyNames() const;
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 24863d2c..15400711 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -105,6 +105,11 @@ inline std::string GetNativeErrorMessage()
(objectid) << \
std::dec
+#define BOX_FORMAT_TIMESPEC(timespec) \
+ timespec.tv_sec << \
+ std::setw(6) << \
+ timespec.tv_usec
+
#undef ERROR
namespace Log
diff --git a/lib/httpserver/HTTPRequest.h b/lib/httpserver/HTTPRequest.h
index ca50e60f..25effb70 100644
--- a/lib/httpserver/HTTPRequest.h
+++ b/lib/httpserver/HTTPRequest.h
@@ -49,7 +49,8 @@ private:
HTTPRequest &operator=(const HTTPRequest &);
public:
typedef std::multimap<std::string, std::string> Query_t;
- typedef std::pair<std::string, std::string> QueryEn_t, Header;
+ typedef Query_t::value_type QueryEn_t;
+ typedef std::pair<std::string, std::string> Header;
enum
{
diff --git a/lib/raidfile/RaidFileWrite.cpp b/lib/raidfile/RaidFileWrite.cpp
index 2d852f86..f24c2422 100644
--- a/lib/raidfile/RaidFileWrite.cpp
+++ b/lib/raidfile/RaidFileWrite.cpp
@@ -836,9 +836,9 @@ int RaidFileWrite::Read(void *pBuffer, int NBytes, int Timeout)
// --------------------------------------------------------------------------
void RaidFileWrite::Close()
{
- BOX_WARNING("RaidFileWrite::Close() called, discarding file");
if(mOSFileHandle != -1)
{
+ BOX_WARNING("RaidFileWrite::Close() called, discarding file");
Discard();
}
}
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp
index c4026395..8b4f1d0c 100644
--- a/lib/server/Daemon.cpp
+++ b/lib/server/Daemon.cpp
@@ -19,6 +19,10 @@
#include <string.h>
#include <stdarg.h>
+#ifdef HAVE_BSD_UNISTD_H
+ #include <bsd/unistd.h>
+#endif
+
#ifdef WIN32
#include <ws2tcpip.h>
#endif
diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp
index 3a56661a..db9974d2 100644
--- a/lib/win32/emu.cpp
+++ b/lib/win32/emu.cpp
@@ -1365,7 +1365,7 @@ void closelog(void)
void syslog(int loglevel, const char *frmt, ...)
{
WORD errinfo;
- char buffer[1024];
+ char buffer[4096];
std::string sixfour(frmt);
switch (loglevel)
@@ -1814,7 +1814,7 @@ bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo)
if (time_breakdown == NULL)
{
::syslog(LOG_ERR, "Error: failed to convert time format: "
- "%d is not a valid time\n", from);
+ "%d is not a valid time\n", adjusted);
return false;
}