From 169413dcf101ca39aebc2bf46991c27c1e439259 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jan 2010 16:43:20 +0100 Subject: cmdline/apt-cdrom.cc: add --auto-detect --- cmdline/apt-cdrom.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index d804c55e5..fc949ce7b 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -98,6 +98,39 @@ OpProgress* pkgCdromTextStatus::GetOpProgress() return &Progress; }; /*}}}*/ +// SetupAutoDetect /*{{{*/ +bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, int &i) +{ + bool Debug = _config->FindB("Debug::Acquire::cdrom", false); + + vector v = UdevCdroms.Scan(); + if (i >= v.size()) + return false; + + if (Debug) + clog << "Looking at devce " << i + << " DeviveName: " << v[i].DeviceName + << " IsMounted: '" << v[i].Mounted << "'" + << " MountPoint: '" << v[i].MountPath << "'" + << endl; + + if (v[i].Mounted) + { + // set the right options + _config->Set("Acquire::cdrom::mount", v[i].MountPath); + _config->Set("APT::CDROM::NoMount", true); + } else { + MountCdrom("/var/lib/apt/media", v[i].DeviceName); + MountCdrom("/var/lib/apt/media", v[i].DeviceName); + _config->Set("Acquire::cdrom::mount", "/var/lib/apt/media"); + _config->Set("APT::CDROM::NoMount", true); + } + i++; + + return true; +} + /*}}}*/ + // DoAdd - Add a new CDROM /*{{{*/ // --------------------------------------------------------------------- /* This does the main add bit.. We show some status and things. The @@ -106,12 +139,25 @@ OpProgress* pkgCdromTextStatus::GetOpProgress() verify them. Then rewrite the database files */ bool DoAdd(CommandLine &) { - bool res = false; + pkgUdevCdromDevices UdevCdroms; pkgCdromTextStatus log; pkgCdrom cdrom; - res = cdrom.Add(&log); + bool res = false; + + bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); + int count = 0; + + if (AutoDetect && UdevCdroms.Dlopen()) + { + while (AutoDetectCdrom(UdevCdroms, count)) + res &= cdrom.Add(&log); + } else { + res = cdrom.Add(&log); + } + if(res) cout << _("Repeat this process for the rest of the CDs in your set.") << endl; + return res; } /*}}}*/ @@ -120,10 +166,24 @@ bool DoAdd(CommandLine &) /* */ bool DoIdent(CommandLine &) { + pkgUdevCdromDevices UdevCdroms; string ident; pkgCdromTextStatus log; pkgCdrom cdrom; - return cdrom.Ident(ident, &log); + bool res = true; + + bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); + int count = 0; + + if (AutoDetect && UdevCdroms.Dlopen()) + { + while (AutoDetectCdrom(UdevCdroms, count)) + res &= cdrom.Ident(ident, &log); + } else { + return cdrom.Ident(ident, &log); + } + + return res; } /*}}}*/ // ShowHelp - Show the help screen /*{{{*/ @@ -164,6 +224,7 @@ int main(int argc,const char *argv[]) /*{{{*/ { CommandLine::Args Args[] = { {'h',"help","help",0}, + {'a',"auto-detect","Acquire::cdrom::AutoDetect",0}, {'v',"version","version",0}, {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg}, {'r',"rename","APT::CDROM::Rename",0}, -- cgit v1.2.3 From fb503892e3e05132bb7db369440402ff81ea5f8d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jan 2010 20:36:13 +0100 Subject: * cmdline/apt-cdrom.cc: - fixed signed/unsigned warning - create /media mount point if needed - fix initialization for res in DoAdd() * methods/cdrom.cc: - make AptMountPoint a variable --- cmdline/apt-cdrom.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index fc949ce7b..494a7d8df 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -99,7 +99,7 @@ OpProgress* pkgCdromTextStatus::GetOpProgress() }; /*}}}*/ // SetupAutoDetect /*{{{*/ -bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, int &i) +bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, unsigned int &i) { bool Debug = _config->FindB("Debug::Acquire::cdrom", false); @@ -120,9 +120,12 @@ bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, int &i) _config->Set("Acquire::cdrom::mount", v[i].MountPath); _config->Set("APT::CDROM::NoMount", true); } else { - MountCdrom("/var/lib/apt/media", v[i].DeviceName); - MountCdrom("/var/lib/apt/media", v[i].DeviceName); - _config->Set("Acquire::cdrom::mount", "/var/lib/apt/media"); + const char* AptMountPoint = "/media/apt"; + if (!FileExists(AptMountPoint)) + mkdir(AptMountPoint, 0750); + if(MountCdrom(AptMountPoint, v[i].DeviceName) == false) + _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint); + _config->Set("Acquire::cdrom::mount", AptMountPoint); _config->Set("APT::CDROM::NoMount", true); } i++; @@ -142,10 +145,10 @@ bool DoAdd(CommandLine &) pkgUdevCdromDevices UdevCdroms; pkgCdromTextStatus log; pkgCdrom cdrom; - bool res = false; + bool res = true; bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); - int count = 0; + unsigned int count = 0; if (AutoDetect && UdevCdroms.Dlopen()) { @@ -173,7 +176,7 @@ bool DoIdent(CommandLine &) bool res = true; bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); - int count = 0; + unsigned int count = 0; if (AutoDetect && UdevCdroms.Dlopen()) { -- cgit v1.2.3 From ffee221b8d1df28768d30762d72a11289ae747dc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jan 2010 21:08:41 +0100 Subject: add Dir::Media::MountPath config option --- cmdline/apt-cdrom.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 494a7d8df..988a58f20 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -120,11 +120,11 @@ bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, unsigned int &i) _config->Set("Acquire::cdrom::mount", v[i].MountPath); _config->Set("APT::CDROM::NoMount", true); } else { - const char* AptMountPoint = "/media/apt"; + string AptMountPoint = _config->FindDir("Dir::Media::MountPath"); if (!FileExists(AptMountPoint)) - mkdir(AptMountPoint, 0750); + mkdir(AptMountPoint.c_str(), 0750); if(MountCdrom(AptMountPoint, v[i].DeviceName) == false) - _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint); + _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint.c_str()); _config->Set("Acquire::cdrom::mount", AptMountPoint); _config->Set("APT::CDROM::NoMount", true); } -- cgit v1.2.3