浏览代码

* apt-pkg/init.cc:
- added Dir::State::Mirrors
* doc/examples/configure-index:
- added Acquire::mirror::RefreshInterval
* methods/mirror.{cc,h}:
- download the mirror file into Dir::State::Mirrors
- added RefreshInterval option to not ask for the mirror file too often

Michael Vogt 19 年之前
父节点
当前提交
d731f9c574
共有 6 个文件被更改,包括 57 次插入13 次删除
  1. 1 0
      apt-pkg/init.cc
  2. 1 0
      debian/apt.dirs
  3. 6 1
      doc/examples/configure-index
  4. 46 10
      methods/mirror.cc
  5. 1 0
      methods/mirror.h
  6. 2 2
      po/apt-all.pot

+ 1 - 0
apt-pkg/init.cc

@@ -54,6 +54,7 @@ bool pkgInitConfig(Configuration &Cnf)
        
        
    Cnf.Set("Dir::State::lists","lists/");
    Cnf.Set("Dir::State::lists","lists/");
    Cnf.Set("Dir::State::cdroms","cdroms.list");
    Cnf.Set("Dir::State::cdroms","cdroms.list");
+   Cnf.Set("Dir::State::mirrors","mirrors/");
    
    
    // Cache
    // Cache
    Cnf.Set("Dir::Cache","var/cache/apt/");
    Cnf.Set("Dir::Cache","var/cache/apt/");

+ 1 - 0
debian/apt.dirs

@@ -5,5 +5,6 @@ etc/apt
 etc/apt/sources.list.d
 etc/apt/sources.list.d
 var/cache/apt/archives/partial
 var/cache/apt/archives/partial
 var/lib/apt/lists/partial
 var/lib/apt/lists/partial
+var/lib/apt/mirrors/partial
 var/lib/apt/periodic
 var/lib/apt/periodic
 usr/share/bug/apt
 usr/share/bug/apt

+ 6 - 1
doc/examples/configure-index

@@ -160,6 +160,11 @@ Acquire
   {
   {
    Options {"--ignore-time-conflict";}	// not very usefull on a normal system
    Options {"--ignore-time-conflict";}	// not very usefull on a normal system
   };
   };
+
+  mirror
+  {
+   RefreshInterval "360"; // refresh interval in minutes
+  };
 };
 };
 
 
 // Directory layout
 // Directory layout
@@ -258,9 +263,9 @@ Debug
   Acquire::Ftp "false";    // Show ftp command traffic
   Acquire::Ftp "false";    // Show ftp command traffic
   Acquire::Http "false";   // Show http command traffic
   Acquire::Http "false";   // Show http command traffic
   Acquire::gpgv "false";   // Show the gpgv traffic
   Acquire::gpgv "false";   // Show the gpgv traffic
+  Acquire::Mirror "false"; // Show debugging of the mirror method
   aptcdrom "false";        // Show found package files
   aptcdrom "false";        // Show found package files
   IdentCdrom "false";
   IdentCdrom "false";
-  
 }
 }
 
 
 /* Whatever you do, do not use this configuration file!! Take out ONLY
 /* Whatever you do, do not use this configuration file!! Take out ONLY

+ 46 - 10
methods/mirror.cc

@@ -18,6 +18,7 @@
 #include <fstream>
 #include <fstream>
 #include <iostream>
 #include <iostream>
 #include <stdarg.h>
 #include <stdarg.h>
+#include <sys/stat.h>
 
 
 using namespace std;
 using namespace std;
 
 
@@ -28,11 +29,16 @@ using namespace std;
 
 
 /* 
 /* 
  * TODO: 
  * TODO: 
+ * - send expected checksum to the mirror method so that 
+     some checking/falling back can be done here already
+ * - keep the mirror file around in /var/lib/apt/mirrors
+     * can't be put into lists/ because of the listclearer
+     * cleanup by time (mtime relative to the other mtimes)
+ * - use a TTL time the mirror file is fetched again (6h?)
+ * - deal with runing as non-root because we can't write to the lists 
+     dir then -> use the cached mirror file
  * - better method to download than having a pkgAcquire interface here
  * - better method to download than having a pkgAcquire interface here
- * - support keeping the mirror file around (evil listclearer strikes again)
- *   -> /var/lib/apt/mirrors dir? how to cleanup? by time?
- * - provide some TTL time until the mirror file is get again (1h? 6h?)
- * - deal with runing as non-root (we can't write to the lists dir then)
+ * - magicmarker is (a bit) evil
  * - testing :)
  * - testing :)
  */
  */
 
 
@@ -60,6 +66,12 @@ bool MirrorMethod::Configuration(string Message)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
+// clean the mirrors dir based on ttl information
+bool MirrorMethod::Clean(string dir)
+{
+   
+}
+
 
 
 bool MirrorMethod::GetMirrorFile(string uri)
 bool MirrorMethod::GetMirrorFile(string uri)
 {
 {
@@ -69,7 +81,7 @@ bool MirrorMethod::GetMirrorFile(string uri)
    string fetch = BaseUri;
    string fetch = BaseUri;
    fetch.replace(0,strlen("mirror://"),"http://");
    fetch.replace(0,strlen("mirror://"),"http://");
 
 
-   MirrorFile = _config->FindDir("Dir::State::lists") + URItoFileName(BaseUri);
+   MirrorFile = _config->FindDir("Dir::State::mirrors") + URItoFileName(BaseUri);
 
 
    if(Debug) 
    if(Debug) 
    {
    {
@@ -77,19 +89,43 @@ bool MirrorMethod::GetMirrorFile(string uri)
       cerr << "mirror-file: " << MirrorFile << endl;
       cerr << "mirror-file: " << MirrorFile << endl;
    }
    }
 
 
-   // FIXME: fetch it with curl
+   // check the file, if it is not older than RefreshInterval just use it
+   // otherwise try to get a new one
+   if(FileExists(MirrorFile)) 
+   {
+      struct stat buf;
+      time_t t,now,refresh;
+      if(stat(MirrorFile.c_str(), &buf) != 0)
+	 return false;
+      t = std::max(buf.st_mtime, buf.st_ctime);
+      now = time(NULL);
+      refresh = 60*_config->FindI("Acquire::Mirror::RefreshInterval",360);
+      if(t + refresh > now)
+      {
+	 if(Debug)
+	    clog << "Mirror file is in RefreshInterval" << endl;
+	 HasMirrorFile = true;
+	 return true;
+      }
+      if(Debug)
+	 clog << "Mirror file " << MirrorFile << " older than " << refresh << ", re-download it" << endl;
+   }
+
+   // not that great to use pkgAcquire here, but we do not have 
+   // any other way right now
    pkgAcquire Fetcher;
    pkgAcquire Fetcher;
    new pkgAcqFile(&Fetcher, fetch, "", 0, "", "", "", MirrorFile);
    new pkgAcqFile(&Fetcher, fetch, "", 0, "", "", "", MirrorFile);
    bool res = (Fetcher.Run() == pkgAcquire::Continue);
    bool res = (Fetcher.Run() == pkgAcquire::Continue);
-   
-   if(res) 
+   if(res)
       HasMirrorFile = true;
       HasMirrorFile = true;
    Fetcher.Shutdown();
    Fetcher.Shutdown();
-   return true;
+   return res;
 }
 }
 
 
 bool MirrorMethod::SelectMirror()
 bool MirrorMethod::SelectMirror()
 {
 {
+   // FIXME: make the mirror selection more clever, do not 
+   //        just use the first one!
    ifstream in(MirrorFile.c_str());
    ifstream in(MirrorFile.c_str());
    getline(in, Mirror);
    getline(in, Mirror);
    if(Debug)
    if(Debug)
@@ -103,7 +139,7 @@ bool MirrorMethod::SelectMirror()
    depth. */
    depth. */
 bool MirrorMethod::Fetch(FetchItem *Itm)
 bool MirrorMethod::Fetch(FetchItem *Itm)
 {
 {
-   // get mirror information
+   // select mirror only once per session
    if(!HasMirrorFile)
    if(!HasMirrorFile)
    {
    {
       GetMirrorFile(Itm->Uri);
       GetMirrorFile(Itm->Uri);

+ 1 - 0
methods/mirror.h

@@ -34,6 +34,7 @@ class MirrorMethod : public HttpMethod
  protected:
  protected:
    bool GetMirrorFile(string uri);
    bool GetMirrorFile(string uri);
    bool SelectMirror();
    bool SelectMirror();
+   bool Clean(string dir);
    
    
    // we need to overwrite those to transform the url back
    // we need to overwrite those to transform the url back
    virtual void Fail(string Why, bool Transient = false);
    virtual void Fail(string Why, bool Transient = false);

+ 2 - 2
po/apt-all.pot

@@ -2238,12 +2238,12 @@ msgstr ""
 msgid "Please insert the disc labeled: '%s' in the drive '%s' and press enter."
 msgid "Please insert the disc labeled: '%s' in the drive '%s' and press enter."
 msgstr ""
 msgstr ""
 
 
-#: apt-pkg/init.cc:120
+#: apt-pkg/init.cc:121
 #, c-format
 #, c-format
 msgid "Packaging system '%s' is not supported"
 msgid "Packaging system '%s' is not supported"
 msgstr ""
 msgstr ""
 
 
-#: apt-pkg/init.cc:136
+#: apt-pkg/init.cc:137
 msgid "Unable to determine a suitable packaging system type"
 msgid "Unable to determine a suitable packaging system type"
 msgstr ""
 msgstr ""