Quellcode durchsuchen

formatting and reoganization

Wolfgang Ortmann vor 9 Jahren
Ursprung
Commit
fcf2a8c0ba
5 geänderte Dateien mit 480 neuen und 682 gelöschten Zeilen
  1. BIN
      bin/kind
  2. 61 0
      src/filetools.cpp
  3. 1 0
      src/filetools.h
  4. 16 110
      src/kind.ag
  5. 402 572
      src/kind.cpp

BIN
bin/kind


+ 61 - 0
src/filetools.cpp

@@ -162,6 +162,67 @@ void removeLock(const std::string& lockfilename)
   unlink(lockfilename.c_str());
 }
 
+extern void debugPrint(const std::string &s);
+
+int removeDir(const std::string& path)
+{
+  debugPrint("removeDir " + path);
+  DIR* d = opendir(path.c_str());
+
+  int r = -1;
+  if (d)
+    {
+      struct dirent* p;
+
+      r = 0;
+      while (!r && (p = readdir(d)))
+        {
+          int r2 = 0;
+	  std::string fn = p->d_name;
+          if (fn != "." && fn != "..")
+            {
+              fn = path + "/" + fn;
+              debugPrint("-- " + fn);
+              struct stat statbuf;
+              if (lstat(fn.c_str(), &statbuf) == 0)
+                {
+                  if (S_ISLNK(statbuf.st_mode))
+                    {
+                      debugPrint("Remove link " + fn);
+                      r2 = unlink(fn.c_str());
+                    }
+                  else if (S_ISDIR(statbuf.st_mode))
+                    {
+                      debugPrint("Remove dir " + fn);
+                      r2 = removeDir(fn);
+                    }
+                  else
+                    {
+                      debugPrint("Remove file " + fn);
+                      r2 = unlink(fn.c_str());
+                    }
+                }
+              else
+                {
+		  std::cout << "stat(" << fn << ") failed" << std::endl;
+                  // we assume "file" here
+                  r2 = unlink(fn.c_str());
+                }
+            }
+          r = r2;
+        }
+      closedir(d);
+    }
+
+  if (r == 0)
+    {
+      debugPrint("Remove Dir itself " + path);
+      r = rmdir(path.c_str());
+    }
+
+  return r;
+}
+
 #define POPEN_BUFFER_SIZE 2000
 Strings myPopen(const std::string& cmd,
                 int& rc, bool debug,

+ 1 - 0
src/filetools.h

@@ -34,4 +34,5 @@ Strings myPopen(const std::string& cmd,
 void removeLock(const std::string& lockfilename);
 void createLock(const std::string& lockfilename);
 
+int removeDir(const std::string& path);
 #endif

+ 16 - 110
src/kind.ag

@@ -75,6 +75,20 @@ void debugPrint(const string& text)
     cout << "    " << text << endl;
 }
 
+void writeSizes(const string logSizeFile)
+{
+  if (!logSizeFile.empty())
+    {
+      Strings st;
+      for (auto s : sizes)
+	{
+	  string h = s.first + " " + to_string(s.second.first) + " " + to_string(s.second.second);
+	  st.push_back(h);
+	}
+      strings2File(st, logSizeFile);
+    }
+}
+
 void readMasterConfig1(const string& fn, KindConfig& conf)
 {
   verbosePrint("reading master config " + fn);
@@ -335,7 +349,6 @@ void backupVault(const string& vault,
           verbosePrint("syncing (" + rsyncCmd + ")");
           int rc;
           backupResult = myPopen(rsyncCmd, rc, debug, imageFullName + "/rsync-log");
-          // strings2File(backupResult, imageFullName + "/rsync-log");
           if (rc == 0 ||
               rc == 24 || // "no error" or "vanished source files" (ignored)
               rc == 6144) // workaround for wrong exit code ??!!
@@ -372,104 +385,6 @@ void backupVault(const string& vault,
     }
 }
 
-int removeDir(const string& path)
-{
-  debugPrint("removeDir " + path);
-  DIR* d = opendir(path.c_str());
-
-  int r = -1;
-  if (d)
-    {
-      struct dirent* p;
-
-      r = 0;
-      while (!r && (p = readdir(d)))
-        {
-          int r2 = 0;
-          string fn = p->d_name;
-          if (fn != "." && fn != "..")
-            {
-              fn = path + "/" + fn;
-              debugPrint("-- " + fn);
-              struct stat statbuf;
-              if (lstat(fn.c_str(), &statbuf) == 0)
-                {
-                  if (S_ISLNK(statbuf.st_mode))
-                    {
-                      debugPrint("Remove link " + fn);
-                      r2 = unlink(fn.c_str());
-                    }
-                  else if (S_ISDIR(statbuf.st_mode))
-                    {
-                      debugPrint("Remove dir " + fn);
-                      r2 = removeDir(fn);
-                    }
-                  else
-                    {
-                      debugPrint("Remove file " + fn);
-                      r2 = unlink(fn.c_str());
-                    }
-                }
-              else
-                {
-                  cout << "stat(" << fn << ") failed" << endl;
-                  // we assume "file" here
-                  r2 = unlink(fn.c_str());
-                }
-            }
-          r = r2;
-        }
-      closedir(d);
-    }
-
-  if (r == 0)
-    {
-      debugPrint("Remove Dir itself " + path);
-      r = rmdir(path.c_str());
-    }
-
-  return r;
-}
-
-#if 0
-int removeDir(const string& dname)
-{
-  int rc = 0;
-  if (!dryRun)
-    {
-      Strings files;
-      // subdirectories
-      dirList(dname, files);
-      for (unsigned int i = 0; i < files.size(); ++i)
-        {
-          debugPrint("Remove dir " + files[i]);
-          for (unsigned int i = 0; i < files.size(); ++i)
-            rc += removeDir(files[i]);
-        }
-      files.clear();
-
-      // files in directory
-      fileList(dname, files);
-      for (unsigned int i = 0; i < files.size(); ++i)
-        {
-          debugPrint("unlink " + files[i]);
-          if (!dryRun)
-            {
-              if (unlink(files[i].c_str()) != 0)
-                rc++;
-            }
-        }
-      debugPrint("rmdir " + dname);
-
-      // directory
-      if (rmdir(dname.c_str()) != 0)
-        rc++;
-    }
-
-  return rc;
-}
-#endif
-
 void expireVault(const string& vault, KindConfig conf, DateTime now)
 {
   if (!quiet)
@@ -613,7 +528,7 @@ int main(int argc, char* argv[])
 
       banks = conf.getStrings("bank");
       if (banks.empty())
-        throw Exception("read master config", "no banks defined");
+        throw Exception("read master configuration", "no banks defined");
 
       if (listConfig)
         {
@@ -655,16 +570,7 @@ int main(int argc, char* argv[])
         for (unsigned int i = 0; i < vaults.size(); ++i)
           {
             backupVault(vaults[i], conf, imageTime, fullImage);
-            if (!logSizeFile.empty())
-              {
-                Strings st;
-                for (auto s : sizes)
-                  {
-                    string h = s.first + " " + to_string(s.second.first) + " " + to_string(s.second.second);
-                    st.push_back(h);
-                  }
-                strings2File(st, logSizeFile);
-              }
+	    writeSizes(logSizeFile);
           }
 
       if (doExpire)

Datei-Diff unterdrückt, da er zu groß ist
+ 402 - 572
src/kind.cpp


Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.