[Box Backup-commit] COMMIT r3169 - box/trunk/lib/backupstore

subversion at boxbackup.org subversion at boxbackup.org
Wed Aug 21 01:57:18 BST 2013


Author: chris
Date: 2013-08-21 01:57:17 +0100 (Wed, 21 Aug 2013)
New Revision: 3169

Modified:
   box/trunk/lib/backupstore/BackupClientFileAttributes.cpp
   box/trunk/lib/backupstore/BackupClientFileAttributes.h
   box/trunk/lib/backupstore/BackupStoreFile.cpp
   box/trunk/lib/backupstore/BackupStoreFile.h
   box/trunk/lib/backupstore/BackupStoreFileDiff.cpp
   box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp
   box/trunk/lib/backupstore/BackupStoreFileEncodeStream.h
Log:
Pass std::strings to functions instead of const char *, for C++ style.


Modified: box/trunk/lib/backupstore/BackupClientFileAttributes.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupClientFileAttributes.cpp	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupClientFileAttributes.cpp	2013-08-21 00:57:17 UTC (rev 3169)
@@ -364,7 +364,7 @@
 //		Created: 2003/10/07
 //
 // --------------------------------------------------------------------------
-void BackupClientFileAttributes::ReadAttributes(const char *Filename,
+void BackupClientFileAttributes::ReadAttributes(const std::string& Filename,
 	bool ZeroModificationTimes, box_time_t *pModTime,
 	box_time_t *pAttrModTime, int64_t *pFileSize,
 	InodeRefType *pInodeNumber, bool *pHasMultipleLinks)
@@ -373,7 +373,7 @@
 	try
 	{
 		EMU_STRUCT_STAT st;
-		if(EMU_LSTAT(Filename, &st) != 0)
+		if(EMU_LSTAT(Filename.c_str(), &st) != 0)
 		{
 			THROW_SYS_FILE_ERROR("Failed to stat file",
 				Filename, CommonException, OSFileError)
@@ -465,7 +465,7 @@
 //
 // --------------------------------------------------------------------------
 void BackupClientFileAttributes::FillAttributes(
-	StreamableMemBlock &outputBlock, const char *Filename,
+	StreamableMemBlock &outputBlock, const std::string& rFilename,
 	const EMU_STRUCT_STAT &st, bool ZeroModificationTimes
 )
 {
@@ -508,14 +508,16 @@
 //		Created: 2003/10/07
 //
 // --------------------------------------------------------------------------
-void BackupClientFileAttributes::FillAttributesLink(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st)
+void BackupClientFileAttributes::FillAttributesLink(
+	StreamableMemBlock &outputBlock, const std::string& Filename,
+	struct stat &st)
 {
 	// Make sure we're only called for symbolic links
 	ASSERT((st.st_mode & S_IFMT) == S_IFLNK);
 
 	// Get the filename the link is linked to
 	char linkedTo[PATH_MAX+4];
-	int linkedToSize = ::readlink(Filename, linkedTo, PATH_MAX);
+	int linkedToSize = ::readlink(Filename.c_str(), linkedTo, PATH_MAX);
 	if(linkedToSize == -1)
 	{
 		BOX_LOG_SYS_ERROR("Failed to readlink '" << Filename << "'");
@@ -540,7 +542,8 @@
 //		Created: 2005/06/12
 //
 // --------------------------------------------------------------------------
-void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBlock, const char *Filename)
+void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBlock,
+	const std::string& Filename)
 {
 #ifdef HAVE_SYS_XATTR_H
 	int listBufferSize = 10000;
@@ -550,13 +553,13 @@
 	{
 		// This returns an unordered list of attribute names, each 0 terminated,
 		// concatenated together
-		int listSize = ::llistxattr(Filename, list, listBufferSize);
+		int listSize = ::llistxattr(Filename.c_str(), list, listBufferSize);
 
 		if(listSize>listBufferSize)
 		{
 			delete[] list, list = NULL;
 			list = new char[listSize];
-			listSize = ::llistxattr(Filename, list, listSize);
+			listSize = ::llistxattr(Filename.c_str(), list, listSize);
 		}
 
 		if(listSize>0)
@@ -606,7 +609,7 @@
 
 				// Find size of attribute (must call with buffer and length 0 on some platforms,
 				// as -1 is returned if the data doesn't fit.)
-				int valueSize = ::lgetxattr(Filename, attrKey.c_str(), 0, 0);
+				int valueSize = ::lgetxattr(Filename.c_str(), attrKey.c_str(), 0, 0);
 				if(valueSize<0)
 				{
 					BOX_LOG_SYS_ERROR("Failed to get "
@@ -625,7 +628,9 @@
 				}
 
 				// This gets the attribute value (may be text or binary), no termination
-				valueSize = ::lgetxattr(Filename, attrKey.c_str(), buffer+xattrSize, xattrBufferSize-xattrSize);
+				valueSize = ::lgetxattr(Filename.c_str(),
+					attrKey.c_str(), buffer+xattrSize,
+					xattrBufferSize-xattrSize);
 				if(valueSize<0)
 				{
 					BOX_LOG_SYS_ERROR("Failed to get "
@@ -742,7 +747,7 @@
 //		Created: 2003/10/07
 //
 // --------------------------------------------------------------------------
-void BackupClientFileAttributes::WriteAttributes(const char *Filename,
+void BackupClientFileAttributes::WriteAttributes(const std::string& Filename,
 	bool MakeUserWritable) const
 {
 	// Got something loaded
@@ -795,8 +800,8 @@
 			Filename << "'");
 #else
 		// Make a symlink, first deleting anything in the way
-		::unlink(Filename);
-		if(::symlink((char*)(pattr + 1), Filename) != 0)
+		::unlink(Filename.c_str());
+		if(::symlink((char*)(pattr + 1), Filename.c_str()) != 0)
 		{
 			BOX_LOG_SYS_ERROR("Failed to symlink '" << Filename <<
 				"' to '" << (char*)(pattr + 1) << "'");
@@ -815,7 +820,7 @@
 			if((mode & S_IFMT) != S_IFLNK)
 			{
 				// Not a link, use normal chown
-				if(::chown(Filename, ntohl(pattr->UID), ntohl(pattr->GID)) != 0)
+				if(::chown(Filename.c_str(), ntohl(pattr->UID), ntohl(pattr->GID)) != 0)
 				{
 					BOX_LOG_SYS_ERROR("Failed to change "
 						"owner of file "
@@ -825,7 +830,7 @@
 			}
 		#else
 			// use the version which sets things on symlinks
-			if(::lchown(Filename, ntohl(pattr->UID), ntohl(pattr->GID)) != 0)
+			if(::lchown(Filename.c_str(), ntohl(pattr->UID), ntohl(pattr->GID)) != 0)
 			{
 				BOX_LOG_SYS_ERROR("Failed to change owner of "
 					"symbolic link '" << Filename << "'");
@@ -871,7 +876,7 @@
 		#endif
 		
 		// Try to apply
-		if(::utimes(Filename, times) != 0)
+		if(::utimes(Filename.c_str(), times) != 0)
 		{
 			BOX_LOG_SYS_WARNING("Failed to change times of "
 				"file '" << Filename << "' to ctime=" <<
@@ -887,8 +892,8 @@
 
 	// Apply everything else... (allowable mode flags only)
 	// Mode must be done last (think setuid)
-	if(::chmod(Filename, mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID
-		| S_ISGID | S_ISVTX)) != 0)
+	if(::chmod(Filename.c_str(), mode & (S_IRWXU | S_IRWXG | S_IRWXO |
+		S_ISUID | S_ISGID | S_ISVTX)) != 0)
 	{
 		BOX_LOG_SYS_ERROR("Failed to change permissions of file "
 			"'" << Filename << "'");
@@ -971,7 +976,7 @@
 //		Created: 2005/06/13
 //
 // --------------------------------------------------------------------------
-void BackupClientFileAttributes::WriteExtendedAttr(const char *Filename, int xattrOffset) const
+void BackupClientFileAttributes::WriteExtendedAttr(const std::string& Filename, int xattrOffset) const
 {
 #ifdef HAVE_SYS_XATTR_H
 	const char* buffer = static_cast<char*>(mpClearAttributes->GetBuffer());
@@ -1004,7 +1009,8 @@
 		xattrOffset += sizeof(u_int32_t);
 
 		// FIXME: Warn on EOPNOTSUPP
-		if(::lsetxattr(Filename, key, buffer+xattrOffset, valueSize, 0)!=0 && errno!=EOPNOTSUPP)
+		if(::lsetxattr(Filename.c_str(), key, buffer+xattrOffset,
+			valueSize, 0)!=0 && errno!=EOPNOTSUPP)
 		{
 			BOX_LOG_SYS_ERROR("Failed to set extended attributes "
 				"on file '" << Filename << "'");

Modified: box/trunk/lib/backupstore/BackupClientFileAttributes.h
===================================================================
--- box/trunk/lib/backupstore/BackupClientFileAttributes.h	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupClientFileAttributes.h	2013-08-21 00:57:17 UTC (rev 3169)
@@ -43,10 +43,10 @@
 	// Prevent access to base class members accidently
 	void Set();
 
-	void ReadAttributes(const char *Filename, bool ZeroModificationTimes = false,
+	void ReadAttributes(const std::string& Filename, bool ZeroModificationTimes = false,
 		box_time_t *pModTime = 0, box_time_t *pAttrModTime = 0, int64_t *pFileSize = 0,
 		InodeRefType *pInodeNumber = 0, bool *pHasMultipleLinks = 0);
-	void WriteAttributes(const char *Filename, 
+	void WriteAttributes(const std::string& Filename, 
 		bool MakeUserWritable = false) const;
 	void GetModificationTimes(box_time_t *pModificationTime,
 		box_time_t *pAttrModificationTime) const;
@@ -56,15 +56,18 @@
 	static void SetBlowfishKey(const void *pKey, int KeyLength);
 	static void SetAttributeHashSecret(const void *pSecret, int SecretLength);
 	
-	static uint64_t GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname);
-	static void FillExtendedAttr(StreamableMemBlock &outputBlock, const char *Filename);
+	static uint64_t GenerateAttributeHash(EMU_STRUCT_STAT &st,
+		const std::string& Filename, const std::string &leafname);
+	static void FillExtendedAttr(StreamableMemBlock &outputBlock,
+		const std::string& Filename);
 
 private:
 	static void FillAttributes(StreamableMemBlock &outputBlock,
-		const char *Filename, const EMU_STRUCT_STAT &st,
+		const std::string& Filename, const EMU_STRUCT_STAT &st,
 		bool ZeroModificationTimes);
-	static void FillAttributesLink(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st);
-	void WriteExtendedAttr(const char *Filename, int xattrOffset) const;
+	static void FillAttributesLink(StreamableMemBlock &outputBlock,
+		const std::string& Filename, struct stat &st);
+	void WriteExtendedAttr(const std::string& Filename, int xattrOffset) const;
 
 	void RemoveClear() const;
 	void EnsureClearAvailable() const;

Modified: box/trunk/lib/backupstore/BackupStoreFile.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFile.cpp	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupStoreFile.cpp	2013-08-21 00:57:17 UTC (rev 3169)
@@ -74,7 +74,7 @@
 //
 // --------------------------------------------------------------------------
 std::auto_ptr<IOStream> BackupStoreFile::EncodeFile(
-	const char *Filename, int64_t ContainerID,
+	const std::string& Filename, int64_t ContainerID,
 	const BackupStoreFilename &rStoreFilename,
 	int64_t *pModificationTime,
 	ReadLoggingStream::Logger* pLogger,

Modified: box/trunk/lib/backupstore/BackupStoreFile.h
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFile.h	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupStoreFile.h	2013-08-21 00:57:17 UTC (rev 3169)
@@ -121,7 +121,7 @@
 	// Main interface
 	static std::auto_ptr<IOStream> EncodeFile
 	(
-		const char *Filename,
+		const std::string& Filename,
 		int64_t ContainerID, const BackupStoreFilename &rStoreFilename,
 		int64_t *pModificationTime = 0,
 		ReadLoggingStream::Logger* pLogger = NULL,
@@ -129,7 +129,7 @@
 	);
 	static std::auto_ptr<IOStream> EncodeFileDiff
 	(
-		const char *Filename, int64_t ContainerID,
+		const std::string& Filename, int64_t ContainerID,
 		const BackupStoreFilename &rStoreFilename, 
 		int64_t DiffFromObjectID, IOStream &rDiffFromBlockIndex,
 		int Timeout, 

Modified: box/trunk/lib/backupstore/BackupStoreFileDiff.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFileDiff.cpp	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupStoreFileDiff.cpp	2013-08-21 00:57:17 UTC (rev 3169)
@@ -125,7 +125,7 @@
 // --------------------------------------------------------------------------
 std::auto_ptr<IOStream> BackupStoreFile::EncodeFileDiff
 (
-	const char *Filename, int64_t ContainerID,
+	const std::string& Filename, int64_t ContainerID,
 	const BackupStoreFilename &rStoreFilename, int64_t DiffFromObjectID, 
 	IOStream &rDiffFromBlockIndex, int Timeout, DiffTimer *pDiffTimer, 
 	int64_t *pModificationTime, bool *pIsCompletelyDifferent)
@@ -133,7 +133,7 @@
 	// Is it a symlink?
 	{
 		EMU_STRUCT_STAT st;
-		if(EMU_LSTAT(Filename, &st) != 0)
+		if(EMU_LSTAT(Filename.c_str(), &st) != 0)
 		{
 			THROW_EXCEPTION(CommonException, OSFileError)
 		}

Modified: box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp	2013-08-21 00:57:17 UTC (rev 3169)
@@ -111,7 +111,7 @@
 //		Created: 8/12/03
 //
 // --------------------------------------------------------------------------
-void BackupStoreFileEncodeStream::Setup(const char *Filename,
+void BackupStoreFileEncodeStream::Setup(const std::string& Filename,
 	BackupStoreFileEncodeStream::Recipe *pRecipe,
 	int64_t ContainerID, const BackupStoreFilename &rStoreFilename,
 	int64_t *pModificationTime, ReadLoggingStream::Logger* pLogger,

Modified: box/trunk/lib/backupstore/BackupStoreFileEncodeStream.h
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFileEncodeStream.h	2013-02-13 00:27:54 UTC (rev 3168)
+++ box/trunk/lib/backupstore/BackupStoreFileEncodeStream.h	2013-08-21 00:57:17 UTC (rev 3169)
@@ -75,7 +75,7 @@
 		int64_t mOtherFileID;
 	};
 	
-	void Setup(const char *Filename, Recipe *pRecipe, int64_t ContainerID,
+	void Setup(const std::string& Filename, Recipe *pRecipe, int64_t ContainerID,
 		const BackupStoreFilename &rStoreFilename,
 		int64_t *pModificationTime,
 		ReadLoggingStream::Logger* pLogger = NULL,




More information about the Boxbackup-commit mailing list