]> git.saurik.com Git - apt.git/commitdiff
cherry pick r2162.1.7 and r2162.1.8 from the debian-sid branch
authorMichael Vogt <michael.vogt@ubuntu.com>
Fri, 16 Sep 2011 07:40:22 +0000 (09:40 +0200)
committerMichael Vogt <michael.vogt@ubuntu.com>
Fri, 16 Sep 2011 07:40:22 +0000 (09:40 +0200)
apt-pkg/indexrecords.cc
debian/changelog
doc/apt.conf.5.xml
test/integration/framework
test/integration/test-releasefile-valid-until [new file with mode: 0755]

index 10e154ad2305b33c1887bace3777d846d61604b5..ba5b7c84620d72a3ae86d2d9297ad0f5a240ff06 100644 (file)
@@ -113,10 +113,14 @@ bool indexRecords::Load(const string Filename)                            /*{{{*/
    }
    // get the user settings for this archive and use what expires earlier
    int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
    }
    // get the user settings for this archive and use what expires earlier
    int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
-   if (Label.empty() == true)
+   if (Label.empty() == false)
       MaxAge = _config->FindI(string("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
       MaxAge = _config->FindI(string("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
+   int MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
+   if (Label.empty() == false)
+      MinAge = _config->FindI(string("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
 
 
-   if(MaxAge == 0) // No user settings, use the one from the Release file
+   if(MaxAge == 0 &&
+      (MinAge == 0 || ValidUntil == 0)) // No user settings, use the one from the Release file
       return true;
 
    time_t date;
       return true;
 
    time_t date;
@@ -125,10 +129,17 @@ bool indexRecords::Load(const string Filename)                            /*{{{*/
       strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
       return false;
    }
       strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
       return false;
    }
-   date += 24*60*60*MaxAge;
 
 
-   if (ValidUntil == 0 || ValidUntil > date)
-      ValidUntil = date;
+   if (MinAge != 0 && ValidUntil != 0) {
+      time_t const min_date = date + MinAge;
+      if (ValidUntil < min_date)
+        ValidUntil = min_date;
+   }
+   if (MaxAge != 0) {
+      time_t const max_date = date + MaxAge;
+      if (ValidUntil == 0 || ValidUntil > max_date)
+        ValidUntil = max_date;
+   }
 
    return true;
 }
 
    return true;
 }
index 17f7795288a6d5426ca56024a3f7e1dc50ee622b..8d76b229448fd7892071b4357b9c80839157716b 100644 (file)
@@ -8,6 +8,13 @@ apt (0.8.16~exp5ubuntu9) UNRELEASEDoneiric; urgency=low
   * apt-pkg/acquire-item.cc:
     - if no Release.gpg file is found try to verify with hashes,
       but do not fail if a hash can't be found
   * apt-pkg/acquire-item.cc:
     - if no Release.gpg file is found try to verify with hashes,
       but do not fail if a hash can't be found
+  * apt-pkg/indexrecords.cc:
+    - fix Acquire::Max-ValidTime option by interpreting it really
+      as seconds as specified in the manpage and not as days
+    - add an Acquire::Min-ValidTime option (Closes: #640122)
+  * doc/apt.conf.5.xml:
+    - reword Acquire::Max-ValidTime documentation to make clear
+      that it doesn't provide the new Min-ValidTime functionality
 
  -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 16 Sep 2011 09:16:32 +0200
 
 
  -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 16 Sep 2011 09:16:32 +0200
 
index 2634c47a948ecaf24b8bcd4c8c99793d7b888109..1adc868e00721b63c1b6038a4e084162555014be 100644 (file)
@@ -267,14 +267,23 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
 
      <varlistentry><term>Max-ValidTime</term>
         <listitem><para>Seconds the Release file should be considered valid after
 
      <varlistentry><term>Max-ValidTime</term>
         <listitem><para>Seconds the Release file should be considered valid after
-        it was created. The default is "for ever" (0) if the Release file of the
-        archive doesn't include a <literal>Valid-Until</literal> header.
-        If it does then this date is the default. The date from the Release file or
-        the date specified by the creation time of the Release file
-        (<literal>Date</literal> header) plus the seconds specified with this
-        options are used to check if the validation of a file has expired by using
-        the earlier date of the two. Archive specific settings can be made by
-        appending the label of the archive to the option name.
+        it was created (indicated by the <literal>Date</literal> header).
+        If the Release file itself includes a <literal>Valid-Until</literal> header
+        the earlier date of the two is used as the expiration date.
+        The default value is <literal>0</literal> which stands for "for ever".
+        Archive specific settings can be made by appending the label of the archive
+        to the option name.
+        </para></listitem>
+     </varlistentry>
+
+     <varlistentry><term>Min-ValidTime</term>
+        <listitem><para>Minimum of seconds the Release file should be considered
+        valid after it was created (indicated by the <literal>Date</literal> header).
+        Use this if you need to use a seldomly updated (local) mirror of a more
+        regular updated archive with a <literal>Valid-Until</literal> header
+        instead of competely disabling the expiration date checking.
+        Archive specific settings can and should be used by appending the label of
+        the archive to the option name.
         </para></listitem>
      </varlistentry>
 
         </para></listitem>
      </varlistentry>
 
index ccab010e6bc2a32758a8fb79228c8f3977d01446..8937c0a91775d57b30a9ef1ea2f93362849bd58c 100644 (file)
@@ -508,8 +508,9 @@ getcodenamefromsuite() { echo -n "$1"; }
 getreleaseversionfromsuite() { true; }
 
 generatereleasefiles() {
 getreleaseversionfromsuite() { true; }
 
 generatereleasefiles() {
+       # $1 is the Date header and $2 is the ValidUntil header to be set
+       # both should be given in notation date/touch can understand
        msgninfo "\tGenerate Release files… "
        msgninfo "\tGenerate Release files… "
-       local DATE="${1:-now}"
        if [ -e aptarchive/dists ]; then
                for dir in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do
                        aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index
        if [ -e aptarchive/dists ]; then
                for dir in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do
                        aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index
@@ -518,27 +519,31 @@ generatereleasefiles() {
                        local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
                        local CODENAME="$(getcodenamefromsuite $SUITE)"
                        local VERSION="$(getreleaseversionfromsuite $SUITE)"
                        local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
                        local CODENAME="$(getcodenamefromsuite $SUITE)"
                        local VERSION="$(getreleaseversionfromsuite $SUITE)"
-                       if [ -z "$VERSION" ]; then
-                               aptftparchive -qq release $dir \
-                                       -o APT::FTPArchive::Release::Suite="${SUITE}" \
-                                       -o APT::FTPArchive::Release::Codename="${CODENAME}" \
-                                               | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
-                       else
-                               aptftparchive -qq release $dir \
-                                       -o APT::FTPArchive::Release::Suite="${SUITE}" \
-                                       -o APT::FTPArchive::Release::Codename="${CODENAME}" \
-                                       -o APT::FTPArchive::Release::Version="${VERSION}" \
-                                               | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
+                       if [ -n "$VERSION" ]; then
+                               VERSION="-o APT::FTPArchive::Release::Version='${VERSION}'"
                        fi
                        fi
+                       aptftparchive -qq release $dir \
+                               -o APT::FTPArchive::Release::Suite="${SUITE}" \
+                               -o APT::FTPArchive::Release::Codename="${CODENAME}" \
+                               -o APT::FTPArchive::Release::Label="Testcases" \
+                               ${VERSION} \
+                                       | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
                        if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
                                sed -i '/^Date: / a\
 NotAutomatic: yes' $dir/Release
                        fi
                        if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
                                sed -i '/^Date: / a\
 NotAutomatic: yes' $dir/Release
                        fi
+                       if [ -n "$1" -a "$1" != "now" ]; then
+                               sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
+                       fi
+                       if [ -n "$2" ]; then
+                               sed -i "/^Date: / a\
+Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
+                       fi
                done
        else
                aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
        fi
                done
        else
                aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
        fi
-       if [ "$DATE" != "now" ]; then
+       if [ -n "$1" -a "$1" != "now" ]; then
                for release in $(find ./aptarchive -name 'Release'); do
                        touch -d "$1" $release
                done
                for release in $(find ./aptarchive -name 'Release'); do
                        touch -d "$1" $release
                done
diff --git a/test/integration/test-releasefile-valid-until b/test/integration/test-releasefile-valid-until
new file mode 100755 (executable)
index 0000000..c35fe97
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'i386'
+
+insertpackage 'wheezy' 'apt' 'all' '0.8.15'
+
+setupaptarchive
+
+setupreleasefile() {
+       rm -rf rootdir/var/lib/apt/lists
+       aptget clean
+       generatereleasefiles "$1" "$2"
+       signreleasefiles
+}
+
+aptgetupdate() {
+       if aptget update $* 2>&1 | grep -q 'is expired'; then
+               return 1
+       else
+               return 0
+       fi
+}
+
+setupreleasefile
+msgtest 'Release file is accepted as it has' 'no Until'
+aptgetupdate && msgpass || msgfail
+
+setupreleasefile
+msgtest 'Release file is accepted as it has' 'no Until and good Max-Valid'
+aptgetupdate -o Acquire::Max-ValidTime=3600 && msgpass || msgfail
+
+setupreleasefile 'now - 2 days'
+msgtest 'Release file is rejected as it has' 'no Until, but bad Max-Valid'
+aptgetupdate -o Acquire::Max-ValidTime=3600 && msgfail || msgpass
+
+setupreleasefile 'now - 3 days' 'now + 1 day'
+msgtest 'Release file is accepted as it has' 'good Until'
+aptgetupdate && msgpass || msgfail
+
+setupreleasefile 'now - 7 days' 'now - 4 days'
+msgtest 'Release file is rejected as it has' 'bad Until'
+aptgetupdate && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now - 4 days'
+msgtest 'Release file is rejected as it has' 'bad Until (ignore good Max-Valid)'
+aptgetupdate -o Acquire::Max-ValidTime=1209600 && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now - 4 days'
+msgtest 'Release file is rejected as it has' 'bad Max-Valid (bad Until)'
+aptgetupdate -o Acquire::Max-ValidTime=86400 && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now + 4 days'
+msgtest 'Release file is rejected as it has' 'bad Max-Valid (good Until)'
+aptgetupdate -o Acquire::Max-ValidTime=86400 && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now + 4 days'
+msgtest 'Release file is accepted as it has' 'good labeled Max-Valid'
+aptgetupdate -o Acquire::Max-ValidTime=86400 -o Acquire::Max-ValidTime::Testcases=1209600 && msgpass || msgfail
+
+setupreleasefile 'now - 7 days' 'now + 4 days'
+msgtest 'Release file is rejected as it has' 'bad labeled Max-Valid'
+aptgetupdate -o Acquire::Max-ValidTime=1209600 -o Acquire::Max-ValidTime::Testcases=86400 && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now + 1 days'
+msgtest 'Release file is accepted as it has' 'good Until (good Min-Valid, no Max-Valid)'
+aptgetupdate -o Acquire::Min-ValidTime=1209600 && msgpass || msgfail
+
+setupreleasefile 'now - 7 days' 'now - 4 days'
+msgtest 'Release file is accepted as it has' 'good Min-Valid (bad Until, no Max-Valid)'
+aptgetupdate -o Acquire::Min-ValidTime=1209600 && msgpass || msgfail
+
+setupreleasefile 'now - 7 days' 'now - 2 days'
+msgtest 'Release file is accepted as it has' 'good Min-Valid (bad Until, good Max-Valid) <'
+aptgetupdate -o Acquire::Min-ValidTime=1209600 -o Acquire::Max-ValidTime=2419200 && msgpass || msgfail
+
+setupreleasefile 'now - 7 days' 'now - 2 days'
+msgtest 'Release file is rejected as it has' 'bad Max-Valid (bad Until, good Min-Valid) >'
+aptgetupdate -o Acquire::Max-ValidTime=12096 -o Acquire::Min-ValidTime=2419200 && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now - 2 days'
+msgtest 'Release file is rejected as it has' 'bad Max-Valid (bad Until, bad Min-Valid) <'
+aptgetupdate -o Acquire::Min-ValidTime=12096 -o Acquire::Max-ValidTime=241920 && msgfail || msgpass
+
+setupreleasefile 'now - 7 days' 'now - 2 days'
+msgtest 'Release file is rejected as it has' 'bad Max-Valid (bad Until, bad Min-Valid) >'
+aptgetupdate -o Acquire::Max-ValidTime=12096 -o Acquire::Min-ValidTime=241920 && msgfail || msgpass