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

* cmdline/apt-get.cc:
- fix apt-get source pkg=version regression (closes: #561971)
* apt-pkg/contrib/cdromutl.cc:
- fix UnmountCdrom() fails, give it a bit more time and try
the umount again
* methods/cdrom.cc:
- fixes in multi cdrom setup code
- add new "Acquire::cdrom::AutoDetect" variable that enables/disables
the dlopen of libudev for automatic cdrom detection

Michael Vogt лет назад: 16
Родитель
Сommit
972c339a1b
5 измененных файлов с 76 добавлено и 40 удалено
  1. 30 21
      apt-pkg/contrib/cdromutl.cc
  2. 17 7
      cmdline/apt-get.cc
  3. 14 0
      debian/changelog
  4. 4 0
      doc/examples/configure-index
  5. 11 12
      methods/cdrom.cc

+ 30 - 21
apt-pkg/contrib/cdromutl.cc

@@ -64,35 +64,44 @@ bool UnmountCdrom(string Path)
 {
 {
    if (IsMounted(Path) == false)
    if (IsMounted(Path) == false)
       return true;
       return true;
-   
-   int Child = ExecFork();
 
 
-   // The child
-   if (Child == 0)
+   for (int i=0;i<3;i++)
    {
    {
-      // Make all the fds /dev/null
-      for (int I = 0; I != 3; I++)
-	 dup2(open("/dev/null",O_RDWR),I);
+   
+      int Child = ExecFork();
 
 
-      if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
+      // The child
+      if (Child == 0)
       {
       {
-	 if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0)
+	 // Make all the fds /dev/null
+	 for (int I = 0; I != 3; I++)
+	    dup2(open("/dev/null",O_RDWR),I);
+
+	 if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
+	 {
+	    if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0)
+	       _exit(100);
+	    _exit(0);	 	 
+	 }
+	 else
+	 {
+	    const char *Args[10];
+	    Args[0] = "umount";
+	    Args[1] = Path.c_str();
+	    Args[2] = 0;
+	    execvp(Args[0],(char **)Args);      
 	    _exit(100);
 	    _exit(100);
-	 _exit(0);	 	 
+	 }      
       }
       }
-      else
-      {
-	 const char *Args[10];
-	 Args[0] = "umount";
-	 Args[1] = Path.c_str();
-	 Args[2] = 0;
-	 execvp(Args[0],(char **)Args);      
-	 _exit(100);
-      }      
+
+      // if it can not be umounted, give it a bit more time
+      // this can happen when auto-mount magic or fs/cdrom prober attack
+      if (ExecWait(Child,"umount",true) == true)
+	 return true;
+      sleep(1);
    }
    }
 
 
-   // Wait for mount
-   return ExecWait(Child,"umount",true);
+   return false;
 }
 }
 									/*}}}*/
 									/*}}}*/
 // MountCdrom - Mount a cdrom						/*{{{*/
 // MountCdrom - Mount a cdrom						/*{{{*/

+ 17 - 7
cmdline/apt-get.cc

@@ -1299,31 +1299,41 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
 	       {
 	       {
 		  pkgRecords::Parser &Parse = Recs.Lookup(VF);
 		  pkgRecords::Parser &Parse = Recs.Lookup(VF);
 		  Src = Parse.SourcePkg();
 		  Src = Parse.SourcePkg();
+		  // no SourcePkg name, so it is the "binary" name
+		  if (Src.empty() == true)
+		     Src = TmpSrc;
+		  // no Version, so we try the Version of the SourcePkg -
+		  // and after that the version of the binary package
 		  if (VerTag.empty() == true)
 		  if (VerTag.empty() == true)
 		     VerTag = Parse.SourceVer();
 		     VerTag = Parse.SourceVer();
+		  if (VerTag.empty() == true)
+		     VerTag = Ver.VerStr();
 		  break;
 		  break;
 	       }
 	       }
 	    }
 	    }
+	    if (Src.empty() == false)
+	       break;
 	 }
 	 }
 	 if (Src.empty() == true) 
 	 if (Src.empty() == true) 
 	 {
 	 {
-	    if (VerTag.empty() == false)
-	       _error->Warning(_("Ignore unavailable version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str());
-	    else
+	    // Sources files have no codename information
+	    if (VerTag.empty() == true && DefRel.empty() == false)
 	       _error->Warning(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str());
 	       _error->Warning(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str());
-	    VerTag.clear();
 	    DefRel.clear();
 	    DefRel.clear();
 	 }
 	 }
       }
       }
-      if (VerTag.empty() == true && DefRel.empty() == true) 
+      if (Src.empty() == true)
       {
       {
-	 // if we don't have a version or default release, use the CandidateVer to find the Source
+	 // if we don't have found a fitting package yet so we will
+	 // choose a good candidate and proceed with that.
+	 // Maybe we will find a source later on with the right VerTag
 	 pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
 	 pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
 	 if (Ver.end() == false) 
 	 if (Ver.end() == false) 
 	 {
 	 {
 	    pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
 	    pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
 	    Src = Parse.SourcePkg();
 	    Src = Parse.SourcePkg();
-	    VerTag = Parse.SourceVer();
+	    if (VerTag.empty() == true)
+	       VerTag = Parse.SourceVer();
 	 }
 	 }
       }
       }
    }
    }

+ 14 - 0
debian/changelog

@@ -1,3 +1,17 @@
+apt (0.7.25ubuntu3) UNRELEASED; urgency=low
+
+  * cmdline/apt-get.cc:
+    - fix apt-get source pkg=version regression (closes: #561971)
+  * apt-pkg/contrib/cdromutl.cc:
+    - fix UnmountCdrom() fails, give it a bit more time and try
+      the umount again
+  * methods/cdrom.cc:
+    - fixes in multi cdrom setup code
+    - add new "Acquire::cdrom::AutoDetect" variable that enables/disables
+      the dlopen of libudev for automatic cdrom detection
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 18 Dec 2009 16:54:18 +0100
+
 apt (0.7.25ubuntu2) lucid; urgency=low
 apt (0.7.25ubuntu2) lucid; urgency=low
 
 
   * Change history branch so that it does not break the 
   * Change history branch so that it does not break the 

+ 4 - 0
doc/examples/configure-index

@@ -253,6 +253,10 @@ Acquire
   
   
   cdrom
   cdrom
   {
   {
+    // do auto detection of the cdrom mountpoint
+    AutoDetect "true";
+    
+    // cdrom mountpoint (needs to be defined in fstab if AutoDetect is not used)
     mount "/cdrom";
     mount "/cdrom";
 
 
     // You need the trailing slash!
     // You need the trailing slash!

+ 11 - 12
methods/cdrom.cc

@@ -37,8 +37,8 @@ class CDROMMethod : public pkgAcqMethod
    bool MountedByApt;
    bool MountedByApt;
    pkgUdevCdromDevices UdevCdroms;
    pkgUdevCdromDevices UdevCdroms;
  
  
-   bool IsCorrectCD(URI want, string MountPath);
-   bool AutoDetectAndMount(URI);
+   bool IsCorrectCD(URI want, string MountPath, string& NewID);
+   bool AutoDetectAndMount(URI, string &NewID);
    virtual bool Fetch(FetchItem *Itm);
    virtual bool Fetch(FetchItem *Itm);
    string GetID(string Name);
    string GetID(string Name);
    virtual void Exit();
    virtual void Exit();
@@ -92,7 +92,7 @@ string CDROMMethod::GetID(string Name)
 // CDROMMethod::AutoDetectAndMount                                      /*{{{*/
 // CDROMMethod::AutoDetectAndMount                                      /*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* Modifies class varaiable CDROM to the mountpoint */
 /* Modifies class varaiable CDROM to the mountpoint */
-bool CDROMMethod::AutoDetectAndMount(URI Get)
+bool CDROMMethod::AutoDetectAndMount(URI Get, string NewID)
 {
 {
    vector<struct CdromDevice> v = UdevCdroms.Scan();
    vector<struct CdromDevice> v = UdevCdroms.Scan();
 
 
@@ -103,7 +103,7 @@ bool CDROMMethod::AutoDetectAndMount(URI Get)
       {
       {
 	 if (Debug)
 	 if (Debug)
 	    clog << "Checking mounted cdrom device " << v[i].DeviceName << endl;
 	    clog << "Checking mounted cdrom device " << v[i].DeviceName << endl;
-	 if (IsCorrectCD(Get, v[i].MountPath))
+	 if (IsCorrectCD(Get, v[i].MountPath, NewID))
 	 {
 	 {
 	    CDROM = v[i].MountPath;
 	    CDROM = v[i].MountPath;
 	    return true;
 	    return true;
@@ -126,7 +126,7 @@ bool CDROMMethod::AutoDetectAndMount(URI Get)
       {
       {
 	 if(MountCdrom("/media/apt", v[i].DeviceName)) 
 	 if(MountCdrom("/media/apt", v[i].DeviceName)) 
 	 {
 	 {
-	    if (IsCorrectCD(Get, "/media/apt"))
+	    if (IsCorrectCD(Get, "/media/apt", NewID))
 	    {
 	    {
 	       MountedByApt = true;
 	       MountedByApt = true;
 	       CDROM = "/media/apt";
 	       CDROM = "/media/apt";
@@ -144,10 +144,8 @@ bool CDROMMethod::AutoDetectAndMount(URI Get)
 // CDROMMethod::IsCorrectCD                                             /*{{{*/
 // CDROMMethod::IsCorrectCD                                             /*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-bool CDROMMethod::IsCorrectCD(URI want, string MountPath)
+bool CDROMMethod::IsCorrectCD(URI want, string MountPath, string& NewID)
 {
 {
-   string NewID;
-
    for (unsigned int Version = 2; Version != 0; Version--)
    for (unsigned int Version = 2; Version != 0; Version--)
    {
    {
       if (IdentCdrom(MountPath,NewID,Version) == false)
       if (IdentCdrom(MountPath,NewID,Version) == false)
@@ -220,23 +218,24 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       return true;
       return true;
    }
    }
 
 
+   bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true);
    CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
    CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
    if (Debug)
    if (Debug)
       clog << "Looking for CDROM at " << CDROM << endl;
       clog << "Looking for CDROM at " << CDROM << endl;
 
 
    if (CDROM[0] == '.')
    if (CDROM[0] == '.')
       CDROM= SafeGetCWD() + '/' + CDROM;
       CDROM= SafeGetCWD() + '/' + CDROM;
-   string NewID;
 
 
+   string NewID;
    while (CurrentID.empty() == true)
    while (CurrentID.empty() == true)
    {
    {
-      if (CDROM == "apt-udev-auto/") 
-	 AutoDetectAndMount(Get);
+      if (AutoDetect)
+	 AutoDetectAndMount(Get, NewID);
 
 
       if(!IsMounted(CDROM))
       if(!IsMounted(CDROM))
 	 MountedByApt = MountCdrom(CDROM);
 	 MountedByApt = MountCdrom(CDROM);
       
       
-      if (IsCorrectCD(Get, CDROM))
+      if (IsCorrectCD(Get, CDROM, NewID))
 	 break;
 	 break;
 	 
 	 
       // I suppose this should prompt somehow?
       // I suppose this should prompt somehow?