Use scoped_ptr from boost.
authorMichael Vrable <vrable@cs.hmc.edu>
Wed, 19 Jun 2013 17:27:04 +0000 (10:27 -0700)
committerMichael Vrable <vrable@cs.hmc.edu>
Sun, 26 Jan 2014 20:43:43 +0000 (12:43 -0800)
README
cumulus.h [new file with mode: 0644]
main.cc

diff --git a/README b/README
index bb83b25..cb0a0a7 100644 (file)
--- a/README
+++ b/README
@@ -11,6 +11,7 @@ Dependencies:
     http://code.google.com/p/boto
   - paramiko, SSH2 protocol for python (for sftp storage)
     http://www.lag.net/paramiko/
+  - Boost (smart_ptr)
 
 Building should be a simple matter of running "make".  This will produce
 an executable called "cumulus".
diff --git a/cumulus.h b/cumulus.h
new file mode 100644 (file)
index 0000000..25a95a1
--- /dev/null
+++ b/cumulus.h
@@ -0,0 +1,31 @@
+/* Cumulus: Efficient Filesystem Backup to the Cloud
+ * Copyright (C) 2013 The Cumulus Developers
+ * See the AUTHORS file for a list of contributors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Header file with common definitions needed for cumulus. */
+
+#ifndef CUMULUS_CUMULUS_H__
+#define CUMULUS_CUMULUS_H__
+
+/* All Boost includes are grouped here, so we can more easily switch to other
+ * implementations in the future. */
+#include <boost/scoped_ptr.hpp>
+
+using boost::scoped_ptr;
+
+#endif // CUMULUS_CUMULUS_H__
diff --git a/main.cc b/main.cc
index f06f018..9734521 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -46,6 +46,7 @@
 #include <string>
 #include <vector>
 
+#include "cumulus.h"
 #include "exclude.h"
 #include "hash.h"
 #include "localdb.h"
@@ -226,7 +227,7 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
     /* If the file is new or changed, we must read in the contents a block at a
      * time. */
     if (!cached) {
-        Hash *hash = Hash::New();
+        scoped_ptr<Hash> file_hash(Hash::New());
         Subfile subfile(db);
         subfile.load_old_blocks(old_blocks);
 
@@ -240,7 +241,7 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
                 break;
             }
 
-            hash->update(block_buf, bytes);
+            file_hash->update(block_buf, bytes);
 
             // Sparse file processing: if we read a block of all zeroes, encode
             // that explicitly.
@@ -257,10 +258,9 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
             double block_age = 0.0;
             ObjectReference ref;
 
-            Hash *hash = Hash::New();
-            hash->update(block_buf, bytes);
-            string block_csum = hash->digest_str();
-            delete hash;
+            scoped_ptr<Hash> block_hash(Hash::New());
+            block_hash->update(block_buf, bytes);
+            string block_csum = block_hash->digest_str();
 
             if (all_zero) {
                 ref = ObjectReference(ObjectReference::REF_ZERO);
@@ -323,8 +323,7 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
                 status = "old";
         }
 
-        file_info["checksum"] = hash->digest_str();
-        delete hash;
+        file_info["checksum"] = file_hash->digest_str();
     }
 
     // Sanity check: if we are rebuilding the statcache, but the file looks