summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:53:21 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:53:21 +0000
commit6c9079759285e073024f7e3193c990ede2a17cef (patch)
tree63531c42def0cae81cdb543870b5cc2e57d2931b
parente72403e138ccafede3da2115215c46528cd89602 (diff)
CDrom fixes
Author: jgg Date: 1999-04-03 01:05:24 GMT CDrom fixes
-rw-r--r--apt-pkg/contrib/cdromutl.cc69
-rw-r--r--cmdline/apt-cdrom.cc9
-rw-r--r--doc/apt.conf.5.yo6
-rw-r--r--doc/examples/apt.conf12
4 files changed, 70 insertions, 26 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 47eb3efc2..c24970553 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -1,6 +1,6 @@
// -*- 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.
@@ -17,6 +17,7 @@
#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>
@@ -28,11 +29,13 @@
#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;
@@ -50,6 +53,17 @@ bool UnmountCdrom(string Path)
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();
@@ -65,12 +79,21 @@ bool UnmountCdrom(string Path)
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
@@ -93,6 +116,9 @@ bool UnmountCdrom(string Path)
/* 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");
@@ -106,12 +132,21 @@ bool MountCdrom(string Path)
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
diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc
index cd95eafee..cac0f7eff 100644
--- a/cmdline/apt-cdrom.cc
+++ b/cmdline/apt-cdrom.cc
@@ -1,6 +1,6 @@
// -*- 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.
@@ -831,13 +831,10 @@ bool DoAdd(CommandLine &)
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
diff --git a/doc/apt.conf.5.yo b/doc/apt.conf.5.yo
index 145be2294..b089f9b0a 100644
--- a/doc/apt.conf.5.yo
+++ b/doc/apt.conf.5.yo
@@ -125,6 +125,10 @@ or for a specific host (See the sample config file for examples)
dit(bf(cdrom))
CDROM URIs; the only setting for CDROM URIs is the mount point, cdrom::Mount
which must be the mount point for the CDROM drive as specified in /etc/fstab.
+It is possible to provide alternate mount and unmount commands if your
+mount point cannot be listed in the fstab (such as an SMB mount). The syntax
+is to put "/cdrom/"::Mount "foo"; within the cdrom block. It is important to
+have the trailing slash. Unmount commands can be specified using UMount.
enddit()
@@ -204,7 +208,7 @@ manpagesection(EXAMPLES)
bf(/usr/doc/apt/examples/apt.conf) contains a sample configuration file
showing the default values for all possible options.
-mapagesection(FILES)
+manpagesection(FILES)
/etc/apt/apt.conf
manpageseealso()
diff --git a/doc/examples/apt.conf b/doc/examples/apt.conf
index 3895a57b5..4e9ec1660 100644
--- a/doc/examples/apt.conf
+++ b/doc/examples/apt.conf
@@ -1,4 +1,4 @@
-// $Id: apt.conf,v 1.28 1999/03/15 23:05:49 jgg Exp $
+// $Id: apt.conf,v 1.29 1999/04/03 01:05:25 jgg Exp $
/* This file is an index of all APT configuration directives. It should
NOT actually be used as a real config file, though it is a completely
valid file.
@@ -97,7 +97,14 @@ Acquire
cdrom
{
- Mount "/cdrom";
+ Mount "/cdrom";
+
+ // You need the trailing slash!
+ "/cdrom/"
+ {
+ Mount "sleep 1000";
+ UMount "sleep 500";
+ }
};
};
@@ -171,4 +178,5 @@ Debug
pkgInitialize "false"; // This one will dump the configuration space
NoLocking "false";
Acquire::Ftp "false"; // Show ftp command traffic
+ aptcdrom "false"; // Show found package files
}