X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/5633a7c28bb3f7bdc10a2fba41caaeb4d67c17f4..00f419583ba34bc82cd4a7134d7eb492eb1cb817:/cmdline/apt-cdrom.cc diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 204cef366..7367a55a3 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.35 2000/05/10 06:03:52 jgg Exp $ +// $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $ /* ###################################################################### APT CDROM - Tool for handling APT's CDROM database. @@ -19,9 +19,11 @@ #include #include #include - +#include + #include "indexcopy.h" +#include #include #include #include @@ -33,6 +35,8 @@ #include /*}}}*/ +using namespace std; + // FindPackages - Find the package files on the CDROM /*{{{*/ // --------------------------------------------------------------------- /* We look over the cdrom for package files. This is a recursive @@ -60,6 +64,10 @@ bool FindPackages(string CD,vector &List,vector &SList, InfoDir = CD + ".disk/"; } + // Don't look into directories that have been marked to ingore. + if (stat(".aptignr",&Buf) == 0) + return true; + /* Aha! We found some package files. We assume that everything under this dir is controlled by those package files so we don't look down anymore */ @@ -93,7 +101,8 @@ bool FindPackages(string CD,vector &List,vector &SList, //strcmp(Dir->d_name,"source") == 0 || strcmp(Dir->d_name,".disk") == 0 || strcmp(Dir->d_name,"experimental") == 0 || - strcmp(Dir->d_name,"binary-all") == 0) + strcmp(Dir->d_name,"binary-all") == 0 || + strcmp(Dir->d_name,"debian-installer") == 0) continue; // See if the name is a sub directory @@ -119,7 +128,7 @@ bool FindPackages(string CD,vector &List,vector &SList, break; if (chdir(CD.c_str()) != 0) - return _error->Errno("chdir","Unable to change to ",CD.c_str()); + return _error->Errno("chdir","Unable to change to %s",CD.c_str()); }; closedir(D); @@ -133,7 +142,8 @@ bool FindPackages(string CD,vector &List,vector &SList, bool DropBinaryArch(vector &List) { char S[300]; - sprintf(S,"/binary-%s/",_config->Find("Apt::Architecture").c_str()); + snprintf(S,sizeof(S),"/binary-%s/", + _config->Find("Apt::Architecture").c_str()); for (unsigned int I = 0; I < List.size(); I++) { @@ -166,7 +176,7 @@ bool DropBinaryArch(vector &List) // Score - We compute a 'score' for a path /*{{{*/ // --------------------------------------------------------------------- /* Paths are scored based on how close they come to what I consider - normal. That is ones that have 'dist' 'stable' 'frozen' will score + normal. That is ones that have 'dist' 'stable' 'testing' will score higher than ones without. */ int Score(string Path) { @@ -175,7 +185,7 @@ int Score(string Path) Res += 29; if (Path.find("/binary-") != string::npos) Res += 20; - if (Path.find("frozen/") != string::npos) + if (Path.find("testing/") != string::npos) Res += 28; if (Path.find("unstable/") != string::npos) Res += 27; @@ -255,7 +265,7 @@ bool DropRepeats(vector &List,const char *Name) // --------------------------------------------------------------------- /* This takes the list of source list expressed entires and collects similar ones to form a single entry for each dist */ -bool ReduceSourcelist(string CD,vector &List) +void ReduceSourcelist(string CD,vector &List) { sort(List.begin(),List.end()); @@ -269,8 +279,9 @@ bool ReduceSourcelist(string CD,vector &List) string::size_type SSpace = (*I).find(' ',Space + 1); if (SSpace == string::npos) continue; - + string Word1 = string(*I,Space,SSpace-Space); + string Prefix = string(*I,0,Space); for (vector::iterator J = List.begin(); J != I; J++) { // Find a space.. @@ -281,6 +292,8 @@ bool ReduceSourcelist(string CD,vector &List) if (SSpace2 == string::npos) continue; + if (string(*J,0,Space2) != Prefix) + continue; if (string(*J,Space2,SSpace2-Space2) != Word1) continue; @@ -358,7 +371,8 @@ bool WriteSourceList(string Name,vector &List,bool Source) string File = _config->FindFile("Dir::Etc::sourcelist"); // Open the stream for reading - ifstream F(File.c_str(),ios::in | ios::nocreate); + ifstream F((FileExists(File)?File.c_str():"/dev/null"), + ios::in ); if (!F != 0) return _error->Errno("ifstream::ifstream","Opening %s",File.c_str()); @@ -577,6 +591,12 @@ bool DoAdd(CommandLine &) if (Name.empty() == false) { + // Escape special characters + string::iterator J = Name.begin(); + for (; J != Name.end(); J++) + if (*J == '"' || *J == ']' || *J == '[') + *J = '_'; + cout << "Found label '" << Name << "'" << endl; Database.Set("CD::" + ID + "::Label",Name); } @@ -663,37 +683,78 @@ bool DoAdd(CommandLine &) return true; } /*}}}*/ +// DoIdent - Ident a CDROM /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool DoIdent(CommandLine &) +{ + // Startup + string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/"); + if (CDROM[0] == '.') + CDROM= SafeGetCWD() + '/' + CDROM; + + cout << "Using CD-ROM mount point " << CDROM << endl; + cout << "Mounting CD-ROM" << endl; + if (MountCdrom(CDROM) == false) + return _error->Error("Failed to mount the cdrom."); + + // Hash the CD to get an ID + cout << "Identifying.. " << flush; + string ID; + if (IdentCdrom(CDROM,ID) == false) + { + cout << endl; + return false; + } + + cout << '[' << ID << ']' << endl; + + // Read the database + Configuration Database; + string DFile = _config->FindFile("Dir::State::cdroms"); + if (FileExists(DFile) == true) + { + if (ReadConfigFile(Database,DFile) == false) + return _error->Error("Unable to read the cdrom database %s", + DFile.c_str()); + } + cout << "Stored Label: '" << Database.Find("CD::" + ID) << "'" << endl; + return true; +} + /*}}}*/ // ShowHelp - Show the help screen /*{{{*/ // --------------------------------------------------------------------- /* */ int ShowHelp() { - cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE << - " compiled on " << __DATE__ << " " << __TIME__ << endl; + ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION, + COMMON_OS,COMMON_CPU,__DATE__,__TIME__); if (_config->FindB("version") == true) - return 100; - - cout << "Usage: apt-cdrom [options] command" << endl; - cout << endl; - cout << "apt-cdrom is a tool to add CDROM's to APT's source list. The " << endl; - cout << "CDROM mount point and device information is taken from apt.conf" << endl; - cout << "and /etc/fstab." << endl; - cout << endl; - cout << "Commands:" << endl; - cout << " add - Add a CDROM" << endl; - cout << endl; - cout << "Options:" << endl; - cout << " -h This help text" << endl; - cout << " -d CD-ROM mount point" << endl; - cout << " -r Rename a recognized CD-ROM" << endl; - cout << " -m No mounting" << endl; - cout << " -f Fast mode, don't check package files" << endl; - cout << " -a Thorough scan mode" << endl; - cout << " -c=? Read this configuration file" << endl; - cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl; - cout << "See fstab(5)" << endl; - return 100; + return 0; + + cout << + "Usage: apt-cdrom [options] command\n" + "\n" + "apt-cdrom is a tool to add CDROM's to APT's source list. The\n" + "CDROM mount point and device information is taken from apt.conf\n" + "and /etc/fstab.\n" + "\n" + "Commands:\n" + " add - Add a CDROM\n" + " ident - Report the identity of a CDROM\n" + "\n" + "Options:\n" + " -h This help text\n" + " -d CD-ROM mount point\n" + " -r Rename a recognized CD-ROM\n" + " -m No mounting\n" + " -f Fast mode, don't check package files\n" + " -a Thorough scan mode\n" + " -c=? Read this configuration file\n" + " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n" + "See fstab(5)\n"; + return 0; } /*}}}*/ @@ -715,12 +776,18 @@ int main(int argc,const char *argv[]) {0,0,0,0}}; CommandLine::Dispatch Cmds[] = { {"add",&DoAdd}, + {"ident",&DoIdent}, {0,0}}; - + + // Set up gettext support + setlocale(LC_ALL,""); + textdomain(PACKAGE); + // Parse the command line and initialize the package library CommandLine CmdL(Args,_config); - if (pkgInitialize(*_config) == false || - CmdL.Parse(argc,argv) == false) + if (pkgInitConfig(*_config) == false || + CmdL.Parse(argc,argv) == false || + pkgInitSystem(*_config,_system) == false) { _error->DumpErrors(); return 100; @@ -732,7 +799,7 @@ int main(int argc,const char *argv[]) return ShowHelp(); // Deal with stdout not being a tty - if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1) + if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1) _config->Set("quiet","1"); // Match the operation