From c189f87d57844a13619ec387916f49aba171c1b3 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 6 Jan 2014 08:12:28 +0100 Subject: flock() the file edited in edit-sources --- apt-private/private-sources.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apt-private/private-sources.cc b/apt-private/private-sources.cc index 65706e785..41cf6b313 100644 --- a/apt-private/private-sources.cc +++ b/apt-private/private-sources.cc @@ -32,6 +32,10 @@ bool EditSources(CommandLine &CmdL) if (FileExists(sourceslist)) before.FromFile(sourceslist); + int lockfd = GetLock(sourceslist); + if (lockfd < 0) + return false; + do { EditFileInSensibleEditor(sourceslist); _error->PushToStack(); @@ -46,6 +50,7 @@ bool EditSources(CommandLine &CmdL) } _error->RevertToStack(); } while (res == false); + close(lockfd); if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) { strprintf( -- cgit v1.2.3 From 3bdf7da5b40636376699aa8a976aae1b279ef356 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 16 Jan 2014 16:45:11 +0100 Subject: add --manual-installed commandline switch --- apt-private/private-cacheset.cc | 9 +++++++++ apt-private/private-cmndline.cc | 1 + 2 files changed, 10 insertions(+) diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc index 6fb224010..a7dc0e800 100644 --- a/apt-private/private-cacheset.cc +++ b/apt-private/private-cacheset.cc @@ -52,6 +52,15 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, output_set.insert(policy->GetCandidateVer(P)); } } + else if (_config->FindB("APT::Cmd::Manual-Installed") == true) + { + if (P.CurrentVer() && + ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false) + { + pkgPolicy *policy = CacheFile.GetPolicy(); + output_set.insert(policy->GetCandidateVer(P)); + } + } else { pkgPolicy *policy = CacheFile.GetPolicy(); diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 28309af07..d6d7bca64 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -226,6 +226,7 @@ bool addArgumentsAPT(std::vector &Args, char const * const Cm { addArg(0,"installed","APT::Cmd::Installed",0); addArg(0,"upgradable","APT::Cmd::Upgradable",0); + addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0); addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0); addArg('a', "all-versions", "APT::Cmd::All-Versions", 0); } -- cgit v1.2.3 From 2a79257e96010318c4bc6d2f2e3e9c475e5bf445 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 16 Jan 2014 18:26:07 +0100 Subject: apt-private/private-show.cc: do not show Description-lang: header, the user probably knows his language (thanks to Donkult) --- apt-private/private-show.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index ddc75dbeb..0aa42ecce 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -74,13 +74,12 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, // write the description pkgRecords Recs(*Cache); + // FIXME: show (optionally) all available translations(?) pkgCache::DescIterator Desc = V.TranslatedDescription(); if (Desc.end() == false) { pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); - if (strcmp(Desc.LanguageCode(),"") != 0) - out << "Description-lang: " << Desc.LanguageCode() << std::endl; - out << "Description" << P.LongDesc(); + out << "Description: " << P.LongDesc(); } // write a final newline (after the description) -- cgit v1.2.3 From 82e7f817a434e29df9ec6fbf19acfd8e7cd890e5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 07:48:43 +0100 Subject: add apt upgrade --dist --- apt-private/private-cmndline.cc | 5 +++++ cmdline/apt.cc | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index d6d7bca64..cbb40d42e 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -230,6 +230,11 @@ bool addArgumentsAPT(std::vector &Args, char const * const Cm addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0); addArg('a', "all-versions", "APT::Cmd::All-Versions", 0); } + else if (CmdMatches("upgrade")) + { + // FIXME: find a better term + addArg(0,"dist","APT::Cmd::Dist-Upgrade", CommandLine::Boolean); + } else if (addArgumentsAPTGet(Args, Cmd) || addArgumentsAPTCache(Args, Cmd)) { // we have no (supported) command-name overlaps so far, so we call diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 4bcae0aba..4dc826632 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -86,6 +86,15 @@ bool ShowHelp(CommandLine &CmdL) return true; } +// figure out what kind of upgrade the user wants +bool DoAptUpgrade(CommandLine &CmdL) +{ + if (_config->FindB("Apt::Cmd::Dist-Upgrade")) + return DoDistUpgrade(CmdL); + else + return DoUpgradeWithAllowNewPackages(CmdL); +} + int main(int argc, const char *argv[]) /*{{{*/ { CommandLine::Dispatch Cmds[] = {{"list",&List}, @@ -95,7 +104,7 @@ int main(int argc, const char *argv[]) /*{{{*/ {"install",&DoInstall}, {"remove", &DoInstall}, {"update",&DoUpdate}, - {"upgrade",&DoUpgradeWithAllowNewPackages}, + {"upgrade",&DoAptUpgrade}, // misc {"edit-sources",&EditSources}, // helper -- cgit v1.2.3 From b7159ec8835e61ea3069213d9188be91c109e32c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 07:52:22 +0100 Subject: reword !isatty() warning --- cmdline/apt.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 4dc826632..2d3966e86 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -117,10 +117,9 @@ int main(int argc, const char *argv[]) /*{{{*/ if(!isatty(1)) { std::cerr << std::endl - << "WARNING WARNING " - << argv[0] - << " is *NOT* intended for scripts " - << "use at your own peril^Wrisk" + << "WARNING: " << argv[0] << " " + << "does not have a stable CLI interface yet. " + << "Use with caution in scripts." << std::endl << std::endl; } -- cgit v1.2.3 From 1410955589dc9f0eaa290907cac070b7ebf93b6a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 08:43:14 +0100 Subject: add missing integration test for "apt list" --- apt-private/private-list.cc | 12 ++++++---- apt-private/private-output.cc | 8 ++++--- cmdline/apt.cc | 23 +++++++++++--------- test/integration/framework | 10 +++++---- test/integration/test-apt-binary | 47 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 21 deletions(-) create mode 100755 test/integration/test-apt-binary diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc index a02ebf02d..fbb66d204 100644 --- a/apt-private/private-list.cc +++ b/apt-private/private-list.cc @@ -101,11 +101,15 @@ private: /*}}}*/ void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ pkgCache::PkgIterator P, - std::ostream &outs) + std::ostream &outs, + bool include_summary=true) { for (pkgCache::VerIterator Ver = P.VersionList(); Ver.end() == false; Ver++) - ListSingleVersion(CacheFile, records, Ver, outs); + { + ListSingleVersion(CacheFile, records, Ver, outs, include_summary); + outs << "\n"; + } } /*}}}*/ // list - list package based on criteria /*{{{*/ @@ -136,7 +140,7 @@ bool List(CommandLine &Cmd) PackageNameMatcher matcher(patterns); LocalitySortedVersionSet bag; - OpTextProgress progress; + OpTextProgress progress(*_config); progress.OverallProgress(0, Cache->Head().PackageCount, Cache->Head().PackageCount, @@ -147,7 +151,7 @@ bool List(CommandLine &Cmd) std::stringstream outs; if(_config->FindB("APT::Cmd::All-Versions", false) == true) { - ListAllVersions(CacheFile, records, V.ParentPkg(), outs); + ListAllVersions(CacheFile, records, V.ParentPkg(), outs, includeSummary); output_map.insert(std::make_pair( V.ParentPkg().Name(), outs.str())); } else { diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 91d13f31b..a8bbad9e5 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -114,11 +114,13 @@ std::string GetVersion(pkgCacheFile &CacheFile, pkgCache::VerIterator V)/*{{{*/ pkgCache::PkgIterator P = V.ParentPkg(); if (V == P.CurrentVer()) { + std::string inst_str = DeNull(V.VerStr()); +#if 0 // FIXME: do we want this or something like this? pkgDepCache *DepCache = CacheFile.GetDepCache(); pkgDepCache::StateCache &state = (*DepCache)[P]; - std::string inst_str = DeNull(V.VerStr()); if (state.Upgradable()) return "**"+inst_str; +#endif return inst_str; } @@ -224,11 +226,11 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ else out << GetVersion(CacheFile, V); } - out << " " << GetArchitecture(CacheFile, P) << " "; + out << " " << GetArchitecture(CacheFile, P); if (include_summary) { out << std::endl - << " " << GetShortDescription(CacheFile, records, P) + << " " << GetShortDescription(CacheFile, records, P) << std::endl; } } diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 2d3966e86..8dc4c292a 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -114,16 +114,6 @@ int main(int argc, const char *argv[]) /*{{{*/ std::vector Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv)); - if(!isatty(1)) - { - std::cerr << std::endl - << "WARNING: " << argv[0] << " " - << "does not have a stable CLI interface yet. " - << "Use with caution in scripts." - << std::endl - << std::endl; - } - InitOutput(); // Set up gettext support @@ -149,6 +139,19 @@ int main(int argc, const char *argv[]) /*{{{*/ return 100; } + if(!isatty(STDOUT_FILENO) && + _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false) + { + std::cerr << std::endl + << "WARNING: " << argv[0] << " " + << "does not have a stable CLI interface yet. " + << "Use with caution in scripts." + << std::endl + << std::endl; + } + if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) + _config->Set("quiet","1"); + // See if the help should be shown if (_config->FindB("help") == true || _config->FindB("version") == true || diff --git a/test/integration/framework b/test/integration/framework index a28363768..6620c78dd 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -99,6 +99,7 @@ aptconfig() { runapt apt-config $*; } aptcache() { runapt apt-cache $*; } aptcdrom() { runapt apt-cdrom $*; } aptget() { runapt apt-get $*; } +apt() { runapt apt $*; } aptftparchive() { runapt apt-ftparchive $*; } aptkey() { runapt apt-key $*; } aptmark() { runapt apt-mark $*; } @@ -202,6 +203,7 @@ setupenvironment() { echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf echo 'quiet::NoUpdate "true";' >> aptconfig.conf echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https + echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary export LC_ALL=C export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" configcompression '.' 'gz' #'bz2' 'lzma' 'xz' @@ -288,7 +290,7 @@ setupsimplenativepackage() { local VERSION="$3" local RELEASE="${4:-unstable}" local DEPENDENCIES="$5" - local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} + local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} If you find such a package installed on your system, something went horribly wrong! They are autogenerated und used only by testcases and surf no other propose…"}" @@ -338,7 +340,7 @@ buildsimplenativepackage() { local VERSION="$3" local RELEASE="${4:-unstable}" local DEPENDENCIES="$5" - local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} + local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} If you find such a package installed on your system, something went horribly wrong! They are autogenerated und used only by testcases and surf no other propose…"}" @@ -535,7 +537,7 @@ insertpackage() { local VERSION="$4" local DEPENDENCIES="$5" local PRIORITY="${6:-optional}" - local DESCRIPTION="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} + local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} If you find such a package installed on your system, something went horribly wrong! They are autogenerated und used only by testcases and surf no other propose…"}" @@ -595,7 +597,7 @@ insertinstalledpackage() { local DEPENDENCIES="$4" local PRIORITY="${5:-optional}" local STATUS="${6:-install ok installed}" - local DESCRIPTION="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/installed + local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed If you find such a package installed on your system, something went horribly wrong! They are autogenerated und used only by testcases and surf no other propose…"}" diff --git a/test/integration/test-apt-binary b/test/integration/test-apt-binary new file mode 100755 index 000000000..8d5df9051 --- /dev/null +++ b/test/integration/test-apt-binary @@ -0,0 +1,47 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture "i386" + +insertpackage 'unstable' 'foo' 'all' '1.0' +insertinstalledpackage 'bar' 'i386' '1.0' + +insertinstalledpackage 'foobar' 'i386' '1.0' +insertpackage 'unstable' 'foobar' 'i386' '2.0' + +setupaptarchive + +APTARCHIVE=$(readlink -f ./aptarchive) + +testequal "Listing... +bar/now 1.0 [installed,local] i386 +foo/unstable 1.0 all +foobar/unstable 2.0 [upgradable from: 1.0] i386" apt list + +testequal "Listing... +foo/unstable 1.0 all +foobar/unstable 2.0 [upgradable from: 1.0] i386" apt list "foo*" + +testequal "Listing... +foobar/unstable 2.0 [upgradable from: 1.0] i386" apt list --upgradable + +# FIXME: hm, hm - does it make sense to have this different? shouldn't +# we use "installed,upgradable" consitently? +testequal "Listing... +bar/now 1.0 [installed,local] i386 +foobar/now 1.0 [installed,upgradable to: 2.0] i386" apt list --installed + +testequal "Listing... +foobar/unstable 2.0 [upgradable from: 1.0] i386 +foobar/now 1.0 [installed,upgradable to: 2.0] i386 +" apt list foobar --all-versions + +testequal "Listing... +bar/now 1.0 [installed,local] i386 + an autogenerated dummy bar=1.0/installed +" apt list bar --verbose + -- cgit v1.2.3 From 8a59cc322ac57c6662949e957611ed718a5f5119 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 17 Jan 2014 21:38:23 +0100 Subject: add purge to the apt cmdline --- cmdline/apt.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmdline/apt.cc b/cmdline/apt.cc index 8dc4c292a..61d5d938a 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -71,13 +71,16 @@ bool ShowHelp(CommandLine &CmdL) _("Usage: apt [options] command\n" "\n" "CLI for apt.\n" - "Commands: \n" + "Basic commands: \n" " list - list packages based on package names\n" " search - search in package descriptions\n" " show - show package details\n" "\n" " update - update list of available packages\n" + "\n" " install - install packages\n" + " remove - remove packages\n" + "\n" " upgrade - upgrade the systems packages\n" "\n" " edit-sources - edit the source information file\n" @@ -103,6 +106,7 @@ int main(int argc, const char *argv[]) /*{{{*/ // needs root {"install",&DoInstall}, {"remove", &DoInstall}, + {"purge", &DoInstall}, {"update",&DoUpdate}, {"upgrade",&DoAptUpgrade}, // misc -- cgit v1.2.3