소스 검색

no error for non-existing mountpoints in MountCdrom

The mountpoint might be auto-generated by the mount command so pushing
an error on the stack will confuse the following code and let it believe
an unrecoverable error occured while potentially everything is okay.

Same goes for umount as a non-existing mountpoint is by definition not
mounted.
David Kalnischkies 12 년 전
부모
커밋
454b97a57f
1개의 변경된 파일20개의 추가작업 그리고 8개의 파일을 삭제
  1. 20 8
      apt-pkg/contrib/cdromutl.cc

+ 20 - 8
apt-pkg/contrib/cdromutl.cc

@@ -74,7 +74,13 @@ bool IsMounted(string &Path)
    leave /etc/mtab inconsitant. We drop all messages this produces. */
    leave /etc/mtab inconsitant. We drop all messages this produces. */
 bool UnmountCdrom(string Path)
 bool UnmountCdrom(string Path)
 {
 {
-   if (IsMounted(Path) == false)
+   // do not generate errors, even if the mountpoint does not exist
+   // the mountpoint might be auto-created by the mount command
+   // and a non-existing mountpoint is surely not mounted
+   _error->PushToStack();
+   bool const mounted = IsMounted(Path);
+   _error->RevertToStack();
+   if (mounted == false)
       return true;
       return true;
 
 
    for (int i=0;i<3;i++)
    for (int i=0;i<3;i++)
@@ -86,8 +92,9 @@ bool UnmountCdrom(string Path)
       if (Child == 0)
       if (Child == 0)
       {
       {
 	 // Make all the fds /dev/null
 	 // Make all the fds /dev/null
-	 for (int I = 0; I != 3; I++)
-	    dup2(open("/dev/null",O_RDWR),I);
+	 int const null_fd = open("/dev/null",O_RDWR);
+	 for (int I = 0; I != 3; ++I)
+	    dup2(null_fd, I);
 
 
 	 if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
 	 if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
 	 {
 	 {
@@ -121,19 +128,24 @@ bool UnmountCdrom(string Path)
 /* We fork mount and drop all messages */
 /* We fork mount and drop all messages */
 bool MountCdrom(string Path, string DeviceName)
 bool MountCdrom(string Path, string DeviceName)
 {
 {
-   if (IsMounted(Path) == true)
+   // do not generate errors, even if the mountpoint does not exist
+   // the mountpoint might be auto-created by the mount command
+   _error->PushToStack();
+   bool const mounted = IsMounted(Path);
+   _error->RevertToStack();
+   if (mounted == true)
       return true;
       return true;
-   
+
    int Child = ExecFork();
    int Child = ExecFork();
 
 
    // The child
    // The child
    if (Child == 0)
    if (Child == 0)
    {
    {
       // Make all the fds /dev/null
       // Make all the fds /dev/null
-      int null_fd = open("/dev/null",O_RDWR);
-      for (int I = 0; I != 3; I++)
+      int const null_fd = open("/dev/null",O_RDWR);
+      for (int I = 0; I != 3; ++I)
 	 dup2(null_fd, I);
 	 dup2(null_fd, I);
-      
+
       if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
       if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
       {
       {
 	 if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)
 	 if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)