summaryrefslogtreecommitdiff
path: root/apt-pkg/deb/deblistparser.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2011-02-08 10:27:51 +0100
committerMichael Vogt <mvo@debian.org>2011-02-08 10:27:51 +0100
commit09b8bd3226a68272f98e4020d10348ff26642500 (patch)
tree1394a74a187ce61982c6c8649721de2f543459a1 /apt-pkg/deb/deblistparser.cc
parent7c748f4aa1bd47089672353fd1a401d1c5c94723 (diff)
parent4c6cf49317769725fee34a132c52ec1fe076b8b5 (diff)
merged from lp:~mvo/apt/mvo (which is really lp:~donkult/apt/sid with some updated comments ;)
Diffstat (limited to 'apt-pkg/deb/deblistparser.cc')
-rw-r--r--apt-pkg/deb/deblistparser.cc114
1 files changed, 79 insertions, 35 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 1b3bfd6ae..9201e6a54 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -783,45 +783,89 @@ bool debListParser::Step()
bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
FileFd &File, string component)
{
- pkgTagFile Tags(&File, File.Size() + 256); // XXX
- pkgTagSection Section;
- if (Tags.Step(Section) == false)
- return false;
-
- // FIXME: Do we need it now for multi-arch?
- // mvo: I don't think we need to fill that in (it's unused since apt-0.6)
-// FileI->Architecture = WriteUniqString(Arch);
-
// apt-secure does no longer download individual (per-section) Release
// file. to provide Component pinning we use the section name now
FileI->Component = WriteUniqString(component);
- const char *Start;
- const char *Stop;
- if (Section.Find("Suite",Start,Stop) == true)
- FileI->Archive = WriteUniqString(Start,Stop - Start);
- if (Section.Find("Component",Start,Stop) == true)
- FileI->Component = WriteUniqString(Start,Stop - Start);
- if (Section.Find("Version",Start,Stop) == true)
- FileI->Version = WriteUniqString(Start,Stop - Start);
- if (Section.Find("Origin",Start,Stop) == true)
- FileI->Origin = WriteUniqString(Start,Stop - Start);
- if (Section.Find("Codename",Start,Stop) == true)
- FileI->Codename = WriteUniqString(Start,Stop - Start);
- if (Section.Find("Label",Start,Stop) == true)
- FileI->Label = WriteUniqString(Start,Stop - Start);
- if (Section.Find("Architecture",Start,Stop) == true)
- FileI->Architecture = WriteUniqString(Start,Stop - Start);
-
- if (Section.FindFlag("NotAutomatic",FileI->Flags,
- pkgCache::Flag::NotAutomatic) == false)
- _error->Warning("Bad NotAutomatic flag");
- if (Section.FindFlag("ButAutomaticUpgrades",FileI->Flags,
- pkgCache::Flag::ButAutomaticUpgrades) == false)
- _error->Warning("Bad ButAutomaticUpgrades flag");
- // overrule the NotAutomatic setting if needed as they are both present for compatibility
- else if ((FileI->Flags & pkgCache::Flag::ButAutomaticUpgrades) == pkgCache::Flag::ButAutomaticUpgrades)
- FileI->Flags &= ~pkgCache::Flag::NotAutomatic;
+ FILE* release = fdopen(dup(File.Fd()), "r");
+ if (release == NULL)
+ return false;
+
+ char buffer[101];
+ bool gpgClose = false;
+ while (fgets(buffer, sizeof(buffer), release) != NULL)
+ {
+ size_t len = 0;
+
+ // Skip empty lines
+ for (; buffer[len] == '\r' && buffer[len] == '\n'; ++len);
+ if (buffer[len] == '\0')
+ continue;
+
+ // only evalute the first GPG section
+ if (strncmp("-----", buffer, 5) == 0)
+ {
+ if (gpgClose == true)
+ break;
+ gpgClose = true;
+ continue;
+ }
+
+ // seperate the tag from the data
+ for (; buffer[len] != ':' && buffer[len] != '\0'; ++len);
+ if (buffer[len] == '\0')
+ continue;
+ char* dataStart = buffer + len;
+ for (++dataStart; *dataStart == ' '; ++dataStart);
+ char* dataEnd = dataStart;
+ for (++dataEnd; *dataEnd != '\0'; ++dataEnd);
+
+ // which datastorage need to be updated
+ map_ptrloc* writeTo = NULL;
+ if (buffer[0] == ' ')
+ ;
+ #define APT_PARSER_WRITETO(X, Y) else if (strncmp(Y, buffer, len) == 0) writeTo = &X;
+ APT_PARSER_WRITETO(FileI->Archive, "Suite")
+ APT_PARSER_WRITETO(FileI->Component, "Component")
+ APT_PARSER_WRITETO(FileI->Version, "Version")
+ APT_PARSER_WRITETO(FileI->Origin, "Origin")
+ APT_PARSER_WRITETO(FileI->Codename, "Codename")
+ APT_PARSER_WRITETO(FileI->Label, "Label")
+ #undef APT_PARSER_WRITETO
+ #define APT_PARSER_FLAGIT(X) else if (strncmp(#X, buffer, len) == 0) \
+ pkgTagSection::FindFlag(FileI->Flags, pkgCache::Flag:: X, dataStart, dataEnd-1);
+ APT_PARSER_FLAGIT(NotAutomatic)
+ APT_PARSER_FLAGIT(ButAutomaticUpgrades)
+ #undef APT_PARSER_FLAGIT
+
+ // load all data from the line and save it
+ string data;
+ if (writeTo != NULL)
+ data.append(dataStart, dataEnd);
+ if (sizeof(buffer) - 1 == (dataEnd - buffer))
+ {
+ while (fgets(buffer, sizeof(buffer), release) != NULL)
+ {
+ if (writeTo != NULL)
+ data.append(buffer);
+ if (strlen(buffer) != sizeof(buffer) - 1)
+ break;
+ }
+ }
+ if (writeTo != NULL)
+ {
+ // remove spaces and stuff from the end of the data line
+ for (std::string::reverse_iterator s = data.rbegin();
+ s != data.rend(); ++s)
+ {
+ if (*s != '\r' && *s != '\n' && *s != ' ')
+ break;
+ *s = '\0';
+ }
+ *writeTo = WriteUniqString(data);
+ }
+ }
+ fclose(release);
return !_error->PendingError();
}