]> git.saurik.com Git - apt.git/commitdiff
add check when sources.list changed
authorMichael Vogt <mvo@debian.org>
Tue, 26 Nov 2013 09:32:21 +0000 (10:32 +0100)
committerMichael Vogt <mvo@debian.org>
Tue, 26 Nov 2013 09:32:21 +0000 (10:32 +0100)
apt-pkg/contrib/hashes.cc
apt-pkg/contrib/hashes.h
cmdline/apt.cc

index e1a4318235a8291bf30248fefabd7c8763ab10e4..b4c768db97d193e1c4dc01926341c52105cc3287 100644 (file)
@@ -54,6 +54,26 @@ HashString::HashString(std::string StringedHash)                     /*{{{*/
 }
                                                                        /*}}}*/
 bool HashString::VerifyFile(std::string filename) const                        /*{{{*/
+{
+   std::string fileHash = GetHashForFile(filename);
+
+   if(_config->FindB("Debug::Hashes",false) == true)
+      std::clog << "HashString::VerifyFile: got: " << fileHash << " expected: " << toStr() << std::endl;
+
+   return (fileHash == Hash);
+}
+                                                                       /*}}}*/
+bool HashString::FromFile(std::string filename)                        /*{{{*/
+{
+   // pick the strongest hash
+   if (Type == "")
+      Type = _SupportedHashes[0];
+
+   Hash = GetHashForFile(filename);
+   return true;
+}
+                                                                       /*}}}*/
+std::string HashString::GetHashForFile(std::string filename) const      /*{{{*/
 {
    std::string fileHash;
 
@@ -84,10 +104,7 @@ bool HashString::VerifyFile(std::string filename) const                     /*{{{*/
    }
    Fd.Close();
 
-   if(_config->FindB("Debug::Hashes",false) == true)
-      std::clog << "HashString::VerifyFile: got: " << fileHash << " expected: " << toStr() << std::endl;
-
-   return (fileHash == Hash);
+   return fileHash;
 }
                                                                        /*}}}*/
 const char** HashString::SupportedHashes()
index 0c0b6c6a725869844cde0f73d196e47cb6985d4d..0a8bcd259b8eb686a26e01228d6293f3d4d5b7eb 100644 (file)
@@ -36,7 +36,10 @@ class HashString
  protected:
    std::string Type;
    std::string Hash;
-   static const char * _SupportedHashes[10];
+   static const char* _SupportedHashes[10];
+
+   // internal helper
+   std::string GetHashForFile(std::string filename) const;
 
  public:
    HashString(std::string Type, std::string Hash);
@@ -49,6 +52,10 @@ class HashString
    // verify the given filename against the currently loaded hash
    bool VerifyFile(std::string filename) const;
 
+   // generate a hash string from the given filename
+   bool FromFile(std::string filename);
+
+
    // helper
    std::string toStr() const;                    // convert to str as "type:hash"
    bool empty() const;
index 38610e7313df6b6ebc5209f734ce1e424c836923..47187fac279d219e2fe8cc75466c73dcc40af492 100644 (file)
@@ -41,6 +41,7 @@
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/indexfile.h>
 #include <apt-pkg/metaindex.h>
+#include <apt-pkg/hashes.h>
 
 #include <apti18n.h>
 
 // ---------------------------------------------------------------------
 bool EditSources(CommandLine &CmdL)
 {
-   // FIXME: suport CmdL.FileList to specify sources.list.d files
+   bool res;
+   pkgSourceList sl;
+   std::string outs;
 
+   // FIXME: suport CmdL.FileList to specify sources.list.d files
    std::string sourceslist = _config->FindFile("Dir::Etc::sourcelist");
 
-   // FIXME: take hash before, 
-   //        when changed display message to apt update
-   bool res;
-   pkgSourceList sl;
+   HashString before;
+   before.FromFile(sourceslist);
 
    do {
       EditFileInSensibleEditor(sourceslist);
       _error->PushToStack();
       res = sl.Read(sourceslist);
       if (!res) {
-         std::string outs;
          strprintf(outs, _("Failed to parse %s. Edit again? "),
                    sourceslist.c_str());
          std::cout << outs;
@@ -84,6 +85,13 @@ bool EditSources(CommandLine &CmdL)
       _error->RevertToStack();
    } while (res == false);
 
+   if (!before.VerifyFile(sourceslist)) {
+      strprintf(
+         outs, _("Your '%s' file changed, please run 'apt-get update'."),
+         sourceslist.c_str());
+      std::cout << outs << std::endl;
+   }
+
    return true;
 }
                                                                        /*}}}*/