[Box Backup-commit] COMMIT r1277 - box/chris/merge/lib/backupclient

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Fri, 09 Feb 2007 23:06:53 +0000


Author: chris
Date: 2007-02-09 23:06:53 +0000 (Fri, 09 Feb 2007)
New Revision: 1277

Modified:
   box/chris/merge/lib/backupclient/BackupClientRestore.cpp
Log:
Catch exceptions while writing files, attributes, resume info and checking
file existence (refs #3)


Modified: box/chris/merge/lib/backupclient/BackupClientRestore.cpp
===================================================================
--- box/chris/merge/lib/backupclient/BackupClientRestore.cpp	2007-02-09 22:51:04 UTC (rev 1276)
+++ box/chris/merge/lib/backupclient/BackupClientRestore.cpp	2007-02-09 23:06:53 UTC (rev 1277)
@@ -367,12 +367,34 @@
 			strerror(errno));
 		return Restore_UnknownError;
 	}
-	
-	// Save the resumption information
-	Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
-	
-	// Fetch the directory listing from the server -- getting a list 
-	// of files which is appropriate to the restore type
+
+	// Save the restore info, in case it's needed later
+	try
+	{
+		Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
+	}
+	catch (BoxException &e)
+	{
+		::syslog(LOG_ERR, "Failed to save resume info file %s: %s", 
+			Params.mRestoreResumeInfoFilename.c_str(), e.what());
+		return Restore_UnknownError;
+	}
+	catch(std::exception &e)
+	{
+		::syslog(LOG_ERR, "Failed to save resume info file %s: %s", 
+			Params.mRestoreResumeInfoFilename.c_str(), e.what());
+		return Restore_UnknownError;
+	}
+	catch(...)
+	{
+		::syslog(LOG_ERR, "Failed to save resume info file %s: "
+			"unknown error", 
+			Params.mRestoreResumeInfoFilename.c_str());
+		return Restore_UnknownError;
+	}
+
+	// Fetch the directory listing from the server -- getting a
+	// list of files which is appropriate to the restore type
 	rConnection.QueryListDirectory(
 			DirectoryID,
 			Params.RestoreDeleted?(BackupProtocolClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING),
@@ -387,8 +409,30 @@
 	// Apply attributes to the directory
 	const StreamableMemBlock &dirAttrBlock(dir.GetAttributes());
 	BackupClientFileAttributes dirAttr(dirAttrBlock);
-	dirAttr.WriteAttributes(rLocalDirectoryName.c_str());
 
+	try
+	{
+		dirAttr.WriteAttributes(rLocalDirectoryName.c_str());
+	}
+	catch (BoxException &e)
+	{
+		::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", 
+			rLocalDirectoryName.c_str(), e.what());
+		return Restore_UnknownError;
+	}
+	catch(std::exception &e)
+	{
+		::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", 
+			rLocalDirectoryName.c_str(), e.what());
+		return Restore_UnknownError;
+	}
+	catch(...)
+	{
+		::syslog(LOG_ERR, "Failed to restore attributes for %s: "
+			"unknown error", rLocalDirectoryName.c_str());
+		return Restore_UnknownError;
+	}
+
 	int64_t bytesWrittenSinceLastRestoreInfoSave = 0;
 	
 	// Process files
@@ -415,18 +459,44 @@
 		
 				// Decode the file -- need to do different things depending on whether 
 				// the directory entry has additional attributes
-				if(en->HasAttributes())
+				try
 				{
-					// Use these attributes
-					const StreamableMemBlock &storeAttr(en->GetAttributes());
-					BackupClientFileAttributes attr(storeAttr);
-					BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout(), &attr);
+					if(en->HasAttributes())
+					{
+						// Use these attributes
+						const StreamableMemBlock &storeAttr(en->GetAttributes());
+						BackupClientFileAttributes attr(storeAttr);
+						BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout(), &attr);
+					}
+					else
+					{
+						// Use attributes stored in file
+						BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout());
+					}
 				}
-				else
+				catch (BoxException &e)
 				{
-					// Use attributes stored in file
-					BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout());
+					::syslog(LOG_ERR, "Failed to restore "
+						"file %s: %s", 
+						localFilename.c_str(), 
+						e.what());
+					return Restore_UnknownError;
 				}
+				catch(std::exception &e)
+				{
+					::syslog(LOG_ERR, "Failed to restore "
+						"file %s: %s", 
+						localFilename.c_str(), 
+						e.what());
+					return Restore_UnknownError;
+				}
+				catch(...)
+				{
+					::syslog(LOG_ERR, "Failed to restore "
+						"file %s: unknown error", 
+						localFilename.c_str());
+					return Restore_UnknownError;
+				}
 				
 				// Progress display?
 				if(Params.PrintDots)
@@ -440,15 +510,73 @@
 				
 				// Save restore info?
 				int64_t fileSize;
-				if(FileExists(localFilename.c_str(), &fileSize, true /* treat links as not existing */))
+				int exists;
+
+				try
 				{
+					exists = FileExists(
+						localFilename.c_str(),
+						&fileSize, 
+						true /* treat links as not 
+							existing */);
+				}
+				catch (BoxException &e)
+				{
+					::syslog(LOG_ERR, "Failed to determine "
+						"whether file exists: %s: %s", 
+						localFilename.c_str(), 
+						e.what());
+					return Restore_UnknownError;
+				}
+				catch(std::exception &e)
+				{
+					::syslog(LOG_ERR, "Failed to determine "
+						"whether file exists: %s: %s", 
+						localFilename.c_str(), 
+						e.what());
+					return Restore_UnknownError;
+				}
+				catch(...)
+				{
+					::syslog(LOG_ERR, "Failed to determine "
+						"whether file exists: %s: "
+						"unknown error", 
+						localFilename.c_str());
+					return Restore_UnknownError;
+				}
+
+				if(exists)
+				{
 					// File exists...
 					bytesWrittenSinceLastRestoreInfoSave += fileSize;
 					
 					if(bytesWrittenSinceLastRestoreInfoSave > MAX_BYTES_WRITTEN_BETWEEN_RESTORE_INFO_SAVES)
 					{
 						// Save the restore info, in case it's needed later
-						Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
+						try
+						{
+							Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
+						}
+						catch (BoxException &e)
+						{
+							::syslog(LOG_ERR, "Failed to save resume info file %s: %s", 
+								Params.mRestoreResumeInfoFilename.c_str(), e.what());
+							return Restore_UnknownError;
+						}
+						catch(std::exception &e)
+						{
+							::syslog(LOG_ERR, "Failed to save resume info file %s: %s", 
+								Params.mRestoreResumeInfoFilename.c_str(), e.what());
+							return Restore_UnknownError;
+						}
+						catch(...)
+						{
+							::syslog(LOG_ERR, "Failed to save resume info file %s: "
+								"unknown error", 
+								Params.mRestoreResumeInfoFilename.c_str());
+							return Restore_UnknownError;
+						}
+
 						bytesWrittenSinceLastRestoreInfoSave = 0;
 					}
 				}
@@ -460,7 +588,35 @@
 	if(bytesWrittenSinceLastRestoreInfoSave != 0)
 	{
 		// Save the restore info, in case it's needed later
-		Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename);
+		try
+		{
+			Params.mResumeInfo.Save(
+				Params.mRestoreResumeInfoFilename);
+		}
+		catch (BoxException &e)
+		{
+			::syslog(LOG_ERR, "Failed to save resume info file "
+				"%s: %s", 
+				Params.mRestoreResumeInfoFilename.c_str(),
+				e.what());
+			return Restore_UnknownError;
+		}
+		catch(std::exception &e)
+		{
+			::syslog(LOG_ERR, "Failed to save resume info file "
+				"%s: %s", 
+				Params.mRestoreResumeInfoFilename.c_str(),
+				e.what());
+			return Restore_UnknownError;
+		}
+		catch(...)
+		{
+			::syslog(LOG_ERR, "Failed to save resume info file "
+				"%s: unknown error", 
+				Params.mRestoreResumeInfoFilename.c_str());
+			return Restore_UnknownError;
+		}
+		
 		bytesWrittenSinceLastRestoreInfoSave = 0;
 	}