summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2010-03-12 19:41:30 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2010-03-12 19:41:30 +0100
commit2bb255740bf18b5e0524fe833523303abb5c9051 (patch)
tree5a27be689c8c2d980928eabb8f3f7df422e67432
parent3a4477a4241bcfbc9db541cf34cc75c1f1111b78 (diff)
* apt-pkg/deb/dpkgpm.cc:
- if available store the Commandline in the history * apt-pkg/contrib/cmndline.cc: - save Commandline in Commandline::AsString for logging
-rw-r--r--apt-pkg/contrib/cmndline.cc42
-rw-r--r--apt-pkg/contrib/cmndline.h1
-rw-r--r--apt-pkg/deb/dpkgpm.cc2
-rw-r--r--debian/changelog3
-rw-r--r--test/libapt/commandlineasstring_test.cc39
-rw-r--r--test/libapt/makefile6
6 files changed, 92 insertions, 1 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index bfd53695e..0b16bf51a 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -135,7 +135,9 @@ bool CommandLine::Parse(int argc,const char **argv)
for (; I != argc; I++)
*Files++ = argv[I];
*Files = 0;
-
+
+ SaveInConfig(argc, argv);
+
return true;
}
/*}}}*/
@@ -351,3 +353,41 @@ bool CommandLine::DispatchArg(Dispatch *Map,bool NoMatch)
return false;
}
/*}}}*/
+// CommandLine::SaveInConfig - for output later in a logfile or so /*{{{*/
+// ---------------------------------------------------------------------
+/* We save the commandline here to have it around later for e.g. logging.
+ It feels a bit like a hack here and isn't bulletproof, but it is better
+ than nothing after all. */
+void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * const argv)
+{
+ char cmdline[300];
+ unsigned int length = 0;
+ bool lastWasOption = false;
+ bool closeQuote = false;
+ for (unsigned int i = 0; i < argc; ++i, ++length)
+ {
+ for (unsigned int j = 0; argv[i][j] != '\0' && length < sizeof(cmdline)-1; ++j, ++length)
+ {
+ cmdline[length] = argv[i][j];
+ if (lastWasOption == true && argv[i][j] == '=')
+ {
+ // That is possibly an option: Quote it if it includes spaces,
+ // the benefit is that this will eliminate also most false positives
+ const char* c = &argv[i][j+1];
+ for (; *c != '\0' && *c != ' '; ++c);
+ if (*c == '\0') continue;
+ cmdline[++length] = '"';
+ closeQuote = true;
+ }
+ }
+ if (closeQuote == true)
+ cmdline[length++] = '"';
+ // Problem: detects also --hello
+ if (cmdline[length-1] == 'o')
+ lastWasOption = true;
+ cmdline[length] = ' ';
+ }
+ cmdline[--length] = '\0';
+ _config->Set("CommandLine::AsString", cmdline);
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h
index e28071e81..7c0c71aa7 100644
--- a/apt-pkg/contrib/cmndline.h
+++ b/apt-pkg/contrib/cmndline.h
@@ -60,6 +60,7 @@ class CommandLine
Configuration *Conf;
bool HandleOpt(int &I,int argc,const char *argv[],
const char *&Opt,Args *A,bool PreceedeMatch = false);
+ void static SaveInConfig(unsigned int const &argc, char const * const * const argv);
public:
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index ad1ea77fd..9ba60060c 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -614,6 +614,8 @@ bool pkgDPkgPM::OpenLog()
remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), ");
}
}
+ if (_config->Exists("Commandline::AsString") == true)
+ WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
WriteHistoryTag("Install", install);
WriteHistoryTag("Upgrade", upgrade);
WriteHistoryTag("Downgrade",downgrade);
diff --git a/debian/changelog b/debian/changelog
index b05498f12..506e70a25 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,9 +14,12 @@ apt (0.7.26) UNRELEASED; urgency=low
Thanks to Osamu Aoki for pointing it out! (Closes: #567669)
* apt-pkg/deb/dpkgpm.cc:
- fix error message construction in OpenLog()
+ - if available store the Commandline in the history
* cmdline/apt-get.cc:
- add a --only-upgrade flag to install command (Closes: #572259)
- fix memory leaks in error conditions in DoSource()
+ * apt-pkg/contrib/cmndline.cc:
+ - save Commandline in Commandline::AsString for logging
-- David Kalnischkies <kalnischkies@gmail.com> Fri, 19 Feb 2010 21:21:43 +0100
diff --git a/test/libapt/commandlineasstring_test.cc b/test/libapt/commandlineasstring_test.cc
new file mode 100644
index 000000000..a38957d7e
--- /dev/null
+++ b/test/libapt/commandlineasstring_test.cc
@@ -0,0 +1,39 @@
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/configuration.h>
+
+#include <string>
+
+#include "assert.h"
+
+class CLT: public CommandLine {
+
+ public:
+ std::string static AsString(const char * const * const argv,
+ unsigned int const argc) {
+ std::string const static conf = "Commandline::AsString";
+ _config->Clear(conf);
+ SaveInConfig(argc, argv);
+ return _config->Find(conf);
+ }
+};
+
+#define CMD(y,z) equals(CLT::AsString(argv, y), z);
+
+int main() {
+ {
+ const char* const argv[] = {"apt-get", "install", "-sf"};
+ CMD(3, "apt-get install -sf");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Test"};
+ CMD(5, "apt-cache -s apt -so Debug::test=Test");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test"};
+ CMD(5, "apt-cache -s apt -so Debug::test=\"Das ist ein Test\"");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "--hallo", "test=1.0"};
+ CMD(5, "apt-cache -s apt --hallo test=1.0");
+ }
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 08f581e6d..cb76d5ee6 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -23,3 +23,9 @@ PROGRAM = GetListOfFilesInDir${BASENAME}
SLIBS = -lapt-pkg
SOURCE = getlistoffilesindir_test.cc
include $(PROGRAM_H)
+
+# Program for testing CommandLine reconstruction
+PROGRAM = commandlineasstring${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = commandlineasstring_test.cc
+include $(PROGRAM_H)