Bläddra i källkod

listImageInfo improved

Wolfgang Ortmann 9 år sedan
förälder
incheckning
e030ccbbb8
5 ändrade filer med 506 tillägg och 444 borttagningar
  1. 5 0
      src/DateTime.h
  2. 25 14
      src/kind.ag
  3. 452 430
      src/kind.cpp
  4. 21 0
      src/stringtools.cpp
  5. 3 0
      src/stringtools.h

+ 5 - 0
src/DateTime.h

@@ -47,6 +47,11 @@ public:
     return DateTime(t1.theTime - t2);
   }
 
+  friend time_t operator-(const DateTime& t1, const DateTime& t2)
+  {
+    return t1.theTime - t2.theTime;
+  }
+
   friend bool operator<(const DateTime& t1, const DateTime& t2)
   {
     return t1.theTime < t2.theTime;

+ 25 - 14
src/kind.ag

@@ -205,16 +205,29 @@ Images findImages(const string& vaultpath, const KindConfig& conf, bool all)
 }
 
 void listImageInfo(const string& vault,
-		   KindConfig conf /*Copy!*/ ,
-		   const DateTime& imageTime,
-		   const string& backupSet)
+                   KindConfig conf /*Copy!*/ ,
+                   const DateTime& imageTime,
+                   const string& backupSet)
 {
   readVaultConfig(vault, conf);
   string vaultPath = findVault(vault);
   Images imageList = findImages(vaultPath, conf, true);
-  for (auto img:imageList)
+  for (auto img : imageList)
     {
-      cout << img.name << endl;
+      if (img.series == backupSet || backupSet.empty())
+        {
+          cout << img.name << endl;
+          if (img.valid)
+            {
+              if (img.series != "expire")
+                cout << "backup set: " << img.series << endl;
+              cout << "created: " << img.time.getString() << endl;
+              cout << "expires: " << img.expire.getString() << " -  +" << timeString(img.expire - imageTime) << endl;
+            }
+
+          else
+            cout << "invalid" << endl;
+        }
     }
 }
 
@@ -539,22 +552,20 @@ void backupVault(const string& vault,
                     unlink(lastPath.c_str());
                 }
 
-	      string linkType=conf.getString("lastLink");
-              if (linkType=="hardLink")
+              string linkType = conf.getString("lastLink");
+              if (linkType == "hardLink")
                 {
                   int rc;
                   string hardLinkCommand = "cp -al " + imageFullName + " " + lastPath;
                   Strings res = myPopen(hardLinkCommand, rc, debug);
                 }
-              else if (linkType=="symLink")
+              else if (linkType == "symLink")
                 {
                   // set symlink to last image
                   symlink(imageFullName.c_str(), lastPath.c_str());
                 }
-	      else if (linkType!="null")
-		{
-		  cerr << "invalid Value in \"lastLink\"" << endl;
-		}
+              else if (linkType != "null")
+                cerr << "invalid Value in \"lastLink\"" << endl;
 
               // write expire date to file
               DateTime expireTime;
@@ -686,7 +697,7 @@ int main(int argc, char* argv[])
       conf.add("userExcludeCommand",
                "find %path -type f -iname '*nobackup' -printf '%P\\\\n'");
       conf.add("logSize", "");
-      conf.add("lastLink","symLink");
+      conf.add("lastLink", "symLink");
 
       if (listConfig)
         {
@@ -714,7 +725,7 @@ int main(int argc, char* argv[])
 
       if (listImages)
         {
-	  listImageInfo(vault, conf, imageTime, forcedBackupSet);
+          listImageInfo(vault, conf, imageTime, forcedBackupSet);
           exit(0);
         }
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 452 - 430
src/kind.cpp


+ 21 - 0
src/stringtools.cpp

@@ -195,6 +195,27 @@ time_t stot(const string& str)
   return value;
 }
 
+string timeString(time_t t)
+{
+  int sec = t % 60;
+  t /= 60;
+  int min = t % 60;
+  t /= 60;
+  int hour = t % 24;
+  t /= 24;
+  int days = t;
+  string res;
+  if (days > 0)
+    res += to_string(days) + " days ";
+  if (hour > 0)
+    res += to_string(hour) + " hours ";
+  if (min > 0)
+    res += to_string(min) + " minutes ";
+  if (sec > 0 || res.empty())
+    res += to_string(sec) + " seconds ";
+  return res;
+}
+
 long int getNumber(const string& l)
 {
   // read *all* digits from string l ignoring all other characters

+ 3 - 0
src/stringtools.h

@@ -53,6 +53,9 @@ bool startsWith(const std::string& s, const std::string& start);
 // string to time
 // converts a given string to a time period (in seconds)
 time_t stot(const std::string& s);
+// time_t to string
+// converts a given time period (time_t in seconds) to a string
+std::string timeString(time_t t);
 
 // replaces in string template the placeholder string with the
 // string given as content

Vissa filer visades inte eftersom för många filer har ändrats