Просмотр исходного кода

properly parse comments in apt_preferences and deb822-style sources

apt_preferences and deb822-style sources used the specialized class
pkgUserTagSection to deal with comments before/after a given stanza, but
it couldn't deal with comments in the stanza at all.

codesearch suggests that nobody else does and a vastely superior way of
working with potentially commented files is implemented now, so we can
officially discourage the use of the old incomplete hack class.
David Kalnischkies лет назад: 10
Родитель
Сommit
f6459e646f

+ 2 - 2
apt-pkg/policy.cc

@@ -438,11 +438,11 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
       return true;
       return true;
    
    
    FileFd Fd(File,FileFd::ReadOnly);
    FileFd Fd(File,FileFd::ReadOnly);
-   pkgTagFile TF(&Fd);
+   pkgTagFile TF(&Fd, pkgTagFile::SUPPORT_COMMENTS);
    if (Fd.IsOpen() == false || Fd.Failed())
    if (Fd.IsOpen() == false || Fd.Failed())
       return false;
       return false;
 
 
-   pkgUserTagSection Tags;
+   pkgTagSection Tags;
    while (TF.Step(Tags) == true)
    while (TF.Step(Tags) == true)
    {
    {
       // can happen when there are only comments in a record
       // can happen when there are only comments in a record

+ 2 - 2
apt-pkg/sourcelist.cc

@@ -418,16 +418,16 @@ bool pkgSourceList::ParseFileOldStyle(std::string const &File)
 /* Returns: the number of stanzas parsed*/
 /* Returns: the number of stanzas parsed*/
 bool pkgSourceList::ParseFileDeb822(string const &File)
 bool pkgSourceList::ParseFileDeb822(string const &File)
 {
 {
-   pkgUserTagSection Tags;
    unsigned int i = 1;
    unsigned int i = 1;
 
 
    // see if we can read the file
    // see if we can read the file
    FileFd Fd(File, FileFd::ReadOnly);
    FileFd Fd(File, FileFd::ReadOnly);
-   pkgTagFile Sources(&Fd);
+   pkgTagFile Sources(&Fd, pkgTagFile::SUPPORT_COMMENTS);
    if (Fd.IsOpen() == false || Fd.Failed())
    if (Fd.IsOpen() == false || Fd.Failed())
       return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str());
       return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str());
 
 
    // read step by step
    // read step by step
+   pkgTagSection Tags;
    while (Sources.Step(Tags) == true)
    while (Sources.Step(Tags) == true)
    {
    {
       if(Tags.Exists("Types") == false)
       if(Tags.Exists("Types") == false)

+ 1 - 3
apt-pkg/tagfile.h

@@ -140,9 +140,7 @@ class pkgTagSection
 };
 };
 
 
 
 
-/* For user generated file the parser should be a bit more relaxed in exchange
-   for being a bit slower to allow comments and new lines all over the place */
-class pkgUserTagSection : public pkgTagSection
+class APT_DEPRECATED_MSG("Use pkgTagFile with the SUPPORT_COMMENTS flag instead") pkgUserTagSection : public pkgTagSection
 {
 {
    virtual void TrimRecord(bool BeforeRecord, const char* &End) APT_OVERRIDE;
    virtual void TrimRecord(bool BeforeRecord, const char* &End) APT_OVERRIDE;
 };
 };

+ 2 - 0
test/integration/test-apt-sources-deb822

@@ -15,10 +15,12 @@ BASE='# some comment
 #Types: meep
 #Types: meep
 
 
 Types: deb
 Types: deb
+#Types: deb-src
 URIs: http://ftp.debian.org/debian
 URIs: http://ftp.debian.org/debian
 Suites: stable
 Suites: stable
 Components: main
 Components: main
 Description: summay
 Description: summay
+# comments are ignored
  and the long part'
  and the long part'
 
 
 msgcleantest() {
 msgcleantest() {

+ 25 - 0
test/integration/test-policy-pinning

@@ -315,3 +315,28 @@ Pin-Priority: 0
 testfailureequal "Reading package lists...
 testfailureequal "Reading package lists...
 E: No priority (or zero) specified for pin" \
 E: No priority (or zero) specified for pin" \
  aptget install -s coolstuff -o PinPriority=0
  aptget install -s coolstuff -o PinPriority=0
+
+# Check with comments
+echo "#Package: coolstuff
+#Pin: release n=backports
+#Pin-Priority: 0
+
+# Test
+
+Package: coolstuff
+Pin: release n=backports
+#Pin: release n=unstable
+#Pin-Priority: 999
+Pin-Priority: 999
+#Pin-Priority: 999" > rootdir/etc/apt/preferences
+
+testsuccessequal "coolstuff:
+  Installed: 2.0~bpo1
+  Candidate: 2.0~bpo2
+  Version table:
+     2.0~bpo2 999
+        100 file:${tmppath}/aptarchive backports/main all Packages
+ *** 2.0~bpo1 100
+        100 ${tmppath}/rootdir/var/lib/dpkg/status
+     1.0 500
+        500 file:${tmppath}/aptarchive stable/main all Packages" aptcache policy coolstuff