Bläddra i källkod

- 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

David Kalnischkies 15 år sedan
förälder
incheckning
89500a25b3
4 ändrade filer med 61 tillägg och 13 borttagningar
  1. 15 4
      apt-pkg/indexrecords.cc
  2. 5 1
      debian/changelog
  3. 17 8
      doc/apt.conf.5.xml
  4. 24 0
      test/integration/test-releasefile-valid-until

+ 15 - 4
apt-pkg/indexrecords.cc

@@ -115,8 +115,12 @@ bool indexRecords::Load(const string Filename)				/*{{{*/
    int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
    int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
    if (Label.empty() == false)
    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;
       return true;
 
 
    time_t date;
    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());
       strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
       return false;
       return false;
    }
    }
-   date += 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;
 }
 }

+ 5 - 1
debian/changelog

@@ -31,8 +31,12 @@ apt (0.8.15.7) UNRELEASED; urgency=low
   * apt-pkg/indexrecords.cc:
   * apt-pkg/indexrecords.cc:
     - fix Acquire::Max-ValidTime option by interpreting it really
     - fix Acquire::Max-ValidTime option by interpreting it really
       as seconds as specified in the manpage and not as days
       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
 
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 05 Sep 2011 13:24:37 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com>  Mon, 05 Sep 2011 15:53:12 +0200
 
 
 apt (0.8.15.6) unstable; urgency=low
 apt (0.8.15.6) unstable; urgency=low
 
 

+ 17 - 8
doc/apt.conf.5.xml

@@ -267,14 +267,23 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
 
 
      <varlistentry><term>Max-ValidTime</term>
      <varlistentry><term>Max-ValidTime</term>
 	 <listitem><para>Seconds the Release file should be considered valid after
 	 <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>
 	 </para></listitem>
      </varlistentry>
      </varlistentry>
 
 

+ 24 - 0
test/integration/test-releasefile-valid-until

@@ -64,3 +64,27 @@ aptgetupdate -o Acquire::Max-ValidTime=86400 -o Acquire::Max-ValidTime::Testcase
 setupreleasefile 'now - 7 days' 'now + 4 days'
 setupreleasefile 'now - 7 days' 'now + 4 days'
 msgtest 'Release file is rejected as it has' 'bad labeled Max-Valid'
 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
 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