// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: cdromutl.cc,v 1.2 1999/03/28 01:37:26 jgg Exp $
+// $Id: cdromutl.cc,v 1.3 1999/04/03 01:05:24 jgg Exp $
/* ######################################################################
CDROM Utilities - Some functions to manipulate CDROM mounts.
#include <apt-pkg/error.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/configuration.h>
#include <sys/wait.h>
#include <sys/errno.h>
#include <stdio.h>
/*}}}*/
-// UnmountCdrom - Unmount a cdrom /*{{{*/
+// IsMounted - Returns true if the mount point is mounted /*{{{*/
// ---------------------------------------------------------------------
-/* Forking umount works much better than the umount syscall which can
- leave /etc/mtab inconsitant. We drop all messages this produces. */
-bool UnmountCdrom(string Path)
+/* This is a simple algorithm that should always work, we stat the mount point
+ and the '..' file in the mount point and see if they are on the same device.
+ By definition if they are the same then it is not mounted. This should
+ account for symlinked mount points as well. */
+bool IsMounted(string &Path)
{
if (Path.empty() == true)
return false;
return _error->Errno("stat","Unable to stat the mount point %s",Path.c_str());
if (Buf.st_dev == Buf2.st_dev)
+ return false;
+ return true;
+}
+ /*}}}*/
+// UnmountCdrom - Unmount a cdrom /*{{{*/
+// ---------------------------------------------------------------------
+/* Forking umount works much better than the umount syscall which can
+ leave /etc/mtab inconsitant. We drop all messages this produces. */
+bool UnmountCdrom(string Path)
+{
+ if (IsMounted(Path) == false)
return true;
int Child = fork();
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
- const char *Args[10];
- Args[0] = "umount";
- Args[1] = Path.c_str();
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- exit(100);
+ 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);
+ }
}
// Wait for mount
/* We fork mount and drop all messages */
bool MountCdrom(string Path)
{
+ if (IsMounted(Path) == true)
+ return true;
+
int Child = fork();
if (Child < -1)
return _error->Errno("fork","Failed to fork");
for (int I = 0; I != 3; I++)
dup2(open("/dev/null",O_RDWR),I);
- const char *Args[10];
- Args[0] = "mount";
- Args[1] = Path.c_str();
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- exit(100);
+ if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true)
+ {
+ if (system(_config->Find("Acquire::cdrom::"+Path+"::Mount").c_str()) != 0)
+ _exit(100);
+ _exit(0);
+ }
+ else
+ {
+ const char *Args[10];
+ Args[0] = "mount";
+ Args[1] = Path.c_str();
+ Args[2] = 0;
+ execvp(Args[0],(char **)Args);
+ _exit(100);
+ }
}
// Wait for mount
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: apt-cdrom.cc,v 1.19 1999/03/29 19:28:52 jgg Exp $
+// $Id: apt-cdrom.cc,v 1.20 1999/04/03 01:05:25 jgg Exp $
/* ######################################################################
APT CDROM - Tool for handling APT's CDROM database.
UnmountCdrom(CDROM);
// Mount the new CDROM
- Prompt("Please insert a Disc in the drive and press any key");
+ Prompt("Please insert a Disc in the drive and press enter");
cout << "Mounting CD-ROM" << endl;
if (MountCdrom(CDROM) == false)
- {
- cout << "Failed to mount the cdrom." << endl;
- return false;
- }
+ return _error->Error("Failed to mount the cdrom.");
}
// Hash the CD to get an ID