chiark / gitweb /
--retire no longer fails if a host directory does not exist.
authorRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 8 Jun 2013 12:25:47 +0000 (13:25 +0100)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 8 Jun 2013 12:25:47 +0000 (13:25 +0100)
doc/CHANGES.html
src/Directory.cc
src/RetireVolumes.cc

index d17338e..0977865 100644 (file)
     href="https://github.com/ewxrjk/rsbackup">rsbackup
     in git</a> for detailed change history.</p>
 
+    <h2>Changes In rsbackup 0.TODO</h2>
+
+    <ul>
+
+      <li><code>--retire</code> no longer fails if a host directory
+      has already been removed.</li>
+
+    </ul>
+
     <h2>Changes In rsbackup 0.4.1</h2>
 
     <ul>
index 0eee9e2..a6df26a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright © 2011 Richard Kettlewell.
+// Copyright © 2011, 2013 Richard Kettlewell.
 //
 // 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
@@ -25,7 +25,7 @@ Directory::~Directory() {
 
 void Directory::open(const std::string &path_) {
   if(!(dp = opendir(path_.c_str())))
-    throw IOError("opening " + path_);
+    throw IOError("opening " + path_, errno);
   path = path_;
 }
 
@@ -37,7 +37,7 @@ bool Directory::get(std::string &name) const {
     return true;
   } else {
     if(errno)
-      throw IOError("reading " + path);
+      throw IOError("reading " + path, errno);
     return false;
   }
 }
index b0ed86f..645c63e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright © 2011 Richard Kettlewell.
+// Copyright © 2011, 2013 Richard Kettlewell.
 //
 // 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
@@ -31,20 +31,29 @@ static void removeDirectory(const std::string &path) {
   }
 }
 
+// Remove all volume directories for a host 
 static void removeVolumeSubdirectories(Device *device,
                                        const std::string &hostName) {
   const std::string hostPath = (device->store->path
                                 + PATH_SEP + hostName);
-  Directory d;
-  d.open(hostPath);
-  std::string f;
-  std::vector<std::string> files;
-  while(d.get(f)) {
-    if(f != "." && f != "..")
-      files.push_back(f);
+  try {
+    Directory d;
+    d.open(hostPath);
+    std::string f;
+    std::vector<std::string> files;
+    while(d.get(f)) {
+      if(f != "." && f != "..")
+        files.push_back(f);
+    }
+    for(size_t n = 0; n < files.size(); ++n)
+      removeDirectory(hostPath + PATH_SEP + files[n]);
+  } catch(IOError &e) {
+    if(e.errno_value == ENOENT) {
+      IO::err.writef("INFO: %s: already removed\n", hostPath.c_str());
+      return;
+    }
+    throw;
   }
-  for(size_t n = 0; n < files.size(); ++n)
-    removeDirectory(hostPath + PATH_SEP + files[n]);
 }
 
 // Retire one volume or host