}
/*}}}*/
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;
}
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()
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);
// 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;
#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;
_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;
}
/*}}}*/