summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-extracttemplates.cc11
-rw-r--r--cmdline/apt-get.cc95
-rw-r--r--cmdline/apt-key.in19
3 files changed, 90 insertions, 35 deletions
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index 8fe15fdf9..8e1937113 100644
--- a/cmdline/apt-extracttemplates.cc
+++ b/cmdline/apt-extracttemplates.cc
@@ -47,8 +47,6 @@
using namespace std;
-#define TMPDIR "/tmp"
-
pkgCache *DebFile::Cache = 0;
// DebFile::DebFile - Construct the DebFile object /*{{{*/
@@ -253,14 +251,11 @@ string WriteFile(const char *package, const char *prefix, const char *data)
{
char fn[512];
static int i;
- const char *tempdir = NULL;
-
- tempdir = getenv("TMPDIR");
- if (tempdir == NULL)
- tempdir = TMPDIR;
+ std::string tempdir = GetTempDir();
snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
- _config->Find("APT::ExtractTemplates::TempDir", tempdir).c_str(),
+ _config->Find("APT::ExtractTemplates::TempDir",
+ tempdir.c_str()).c_str(),
package, prefix, getpid(), i++);
FileFd f;
if (data == NULL)
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index 7e59f3d67..8a0772ce2 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -198,18 +198,31 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
pkgSrcRecords &SrcRecs,string &Src,
CacheFile &CacheFile)
{
- string VerTag;
+ string VerTag, UserRequestedVerTag;
+ string ArchTag = "";
string RelTag = _config->Find("APT::Default-Release");
string TmpSrc = Name;
pkgDepCache *Cache = CacheFile.GetDepCache();
- // extract the version/release from the pkgname
- const size_t found = TmpSrc.find_last_of("/=");
- if (found != string::npos) {
- if (TmpSrc[found] == '/')
- RelTag = TmpSrc.substr(found+1);
- else
- VerTag = TmpSrc.substr(found+1);
+ // extract release
+ size_t found = TmpSrc.find_last_of("/");
+ if (found != string::npos)
+ {
+ RelTag = TmpSrc.substr(found+1);
+ TmpSrc = TmpSrc.substr(0,found);
+ }
+ // extract the version
+ found = TmpSrc.find_last_of("=");
+ if (found != string::npos)
+ {
+ VerTag = UserRequestedVerTag = TmpSrc.substr(found+1);
+ TmpSrc = TmpSrc.substr(0,found);
+ }
+ // extract arch
+ found = TmpSrc.find_last_of(":");
+ if (found != string::npos)
+ {
+ ArchTag = TmpSrc.substr(found+1);
TmpSrc = TmpSrc.substr(0,found);
}
@@ -217,10 +230,25 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
install a version and determine the source package name, then look
in the archive for a source package of the same name. */
bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
- const pkgCache::PkgIterator Pkg = Cache->FindPkg(TmpSrc);
+ pkgCache::PkgIterator Pkg;
+ if (ArchTag != "")
+ Pkg = Cache->FindPkg(TmpSrc, ArchTag);
+ else
+ Pkg = Cache->FindPkg(TmpSrc);
+
+ // if we can't find a package but the user qualified with a arch,
+ // error out here
+ if (Pkg.end() && ArchTag != "")
+ {
+ Src = Name;
+ _error->Error(_("Can not find a package for architecture '%s'"),
+ ArchTag.c_str());
+ return 0;
+ }
+
if (MatchSrcOnly == false && Pkg.end() == false)
{
- if(VerTag.empty() == false || RelTag.empty() == false)
+ if(VerTag != "" || RelTag != "" || ArchTag != "")
{
bool fuzzy = false;
// we have a default release, try to locate the pkg. we do it like
@@ -240,6 +268,17 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
if (Ver.end() == true)
break;
}
+
+ // ignore arches that are not for us
+ if (ArchTag != "" && Ver.Arch() != ArchTag)
+ continue;
+
+ // pick highest version for the arch unless the user wants
+ // something else
+ if (ArchTag != "" && VerTag == "" && RelTag == "")
+ if(Cache->VS().CmpVersion(VerTag, Ver.VerStr()) < 0)
+ VerTag = Ver.VerStr();
+
// We match against a concrete version (or a part of this version)
if (VerTag.empty() == false &&
(fuzzy == true || Cache->VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match
@@ -280,6 +319,20 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
break;
}
}
+
+ if (Src == "" && ArchTag != "")
+ {
+ if (VerTag != "")
+ _error->Error(_("Can not find a package '%s' with version '%s'"),
+ Pkg.FullName().c_str(), VerTag.c_str());
+ if (RelTag != "")
+ _error->Error(_("Can not find a package '%s' with release '%s'"),
+ Pkg.FullName().c_str(), RelTag.c_str());
+ Src = Name;
+ return 0;
+ }
+
+
if (Src.empty() == true)
{
// if we don't have found a fitting package yet so we will
@@ -331,17 +384,15 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
const string Ver = Parse->Version();
// See if we need to look for a specific release tag
- if (RelTag != "")
+ if (RelTag != "" && UserRequestedVerTag == "")
{
const string Rel = GetReleaseForSourceRecord(SrcList, Parse);
if (Rel == RelTag)
{
- ioprintf(c1out, "Selectied version '%s' (%s) for %s\n",
- Ver.c_str(), RelTag.c_str(), Src.c_str());
Last = Parse;
Offset = Parse->Offset();
- break;
+ Version = Ver;
}
}
@@ -362,9 +413,13 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
if (VerTag.empty() == false && (VerTag == Ver))
break;
}
+ if (UserRequestedVerTag == "" && Version != "" && RelTag != "")
+ ioprintf(c1out, "Selected version '%s' (%s) for %s\n",
+ Version.c_str(), RelTag.c_str(), Src.c_str());
+
if (Last != 0 || VerTag.empty() == true)
break;
- _error->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
+ _error->Error(_("Can not find version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
return 0;
}
@@ -1481,14 +1536,12 @@ bool DoChangelog(CommandLine &CmdL)
bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
char tmpname[100];
- char* tmpdir = NULL;
+ const char* tmpdir = NULL;
if (downOnly == false)
{
- const char* const tmpDir = getenv("TMPDIR");
- if (tmpDir != NULL && *tmpDir != '\0')
- snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", tmpDir);
- else
- strncpy(tmpname, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname));
+ std::string systemTemp = GetTempDir();
+ snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX",
+ systemTemp.c_str());
tmpdir = mkdtemp(tmpname);
if (tmpdir == NULL)
return _error->Errno("mkdtemp", "mkdtemp failed");
diff --git a/cmdline/apt-key.in b/cmdline/apt-key.in
index 779872b4c..463e4b4b4 100644
--- a/cmdline/apt-key.in
+++ b/cmdline/apt-key.in
@@ -25,6 +25,9 @@ GPG_CMD="$GPG_CMD --no-auto-check-trustdb --trust-model always"
GPG="$GPG_CMD"
+APT_DIR="/"
+eval $(apt-config shell APT_DIR Dir)
+
MASTER_KEYRING='&keyring-master-filename;'
eval $(apt-config shell MASTER_KEYRING APT::Key::MasterKeyring)
ARCHIVE_KEYRING='&keyring-filename;'
@@ -33,7 +36,7 @@ REMOVED_KEYS='&keyring-removed-filename;'
eval $(apt-config shell REMOVED_KEYS APT::Key::RemovedKeys)
ARCHIVE_KEYRING_URI='&keyring-uri;'
eval $(apt-config shell ARCHIVE_KEYRING_URI APT::Key::ArchiveKeyringURI)
-TMP_KEYRING=/var/lib/apt/keyrings/maybe-import-keyring.gpg
+TMP_KEYRING=${APT_DIR}/var/lib/apt/keyrings/maybe-import-keyring.gpg
requires_root() {
if [ "$(id -u)" -ne 0 ]; then
@@ -107,7 +110,11 @@ add_keys_with_verify_against_master_keyring() {
# (otherwise it does not make sense from a security POV)
net_update() {
# Disabled for now as code is insecure (LP: #1013639 (and 857472, 1013128))
- exit 1
+ APT_KEY_NET_UPDATE_ENABLED=""
+ eval $(apt-config shell APT_KEY_NET_UPDATE_ENABLED APT::Key::Net-Update-Enabled)
+ if [ -z "$APT_KEY_NET_UPDATE_ENABLED" ]; then
+ exit 1
+ fi
if [ -z "$ARCHIVE_KEYRING_URI" ]; then
echo >&2 "ERROR: Your distribution is not supported in net-update as no uri for the archive-keyring is set"
@@ -120,15 +127,15 @@ net_update() {
echo >&2 "ERROR: an installed wget is required for a network-based update"
exit 1
fi
- if [ ! -d /var/lib/apt/keyrings ]; then
- mkdir -p /var/lib/apt/keyrings
+ if [ ! -d ${APT_DIR}/var/lib/apt/keyrings ]; then
+ mkdir -p ${APT_DIR}/var/lib/apt/keyrings
fi
- keyring=/var/lib/apt/keyrings/$(basename $ARCHIVE_KEYRING)
+ keyring=${APT_DIR}/var/lib/apt/keyrings/$(basename $ARCHIVE_KEYRING_URI)
old_mtime=0
if [ -e $keyring ]; then
old_mtime=$(stat -c %Y $keyring)
fi
- (cd /var/lib/apt/keyrings; wget --timeout=90 -q -N $ARCHIVE_KEYRING_URI)
+ (cd ${APT_DIR}/var/lib/apt/keyrings; wget --timeout=90 -q -N $ARCHIVE_KEYRING_URI)
if [ ! -e $keyring ]; then
return
fi