X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/bd37d2483cf87cbfcc535bde0f96d64a994912dc..bcae6dd40485fce886c08c101d39226d6aba7022:/cmdline/apt-cdrom.cc diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 4dadb5d40..c43029e5e 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.31 1999/08/25 02:45:01 jgg Exp $ +// $Id: apt-cdrom.cc,v 1.36 2001/02/20 07:03:17 jgg Exp $ /* ###################################################################### APT CDROM - Tool for handling APT's CDROM database. @@ -19,7 +19,8 @@ #include #include #include - +#include + #include "indexcopy.h" #include @@ -91,6 +92,7 @@ bool FindPackages(string CD,vector &List,vector &SList, if (strcmp(Dir->d_name,".") == 0 || strcmp(Dir->d_name,"..") == 0 || //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) continue; @@ -118,7 +120,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); @@ -171,23 +173,27 @@ int Score(string Path) { int Res = 0; if (Path.find("stable/") != string::npos) - Res += 2; + Res += 29; if (Path.find("/binary-") != string::npos) - Res += 2; + Res += 20; if (Path.find("frozen/") != string::npos) - Res += 2; + Res += 28; + if (Path.find("unstable/") != string::npos) + Res += 27; if (Path.find("/dists/") != string::npos) - Res += 4; + Res += 40; if (Path.find("/main/") != string::npos) - Res += 2; + Res += 20; if (Path.find("/contrib/") != string::npos) - Res += 2; + Res += 20; if (Path.find("/non-free/") != string::npos) - Res += 2; + Res += 20; if (Path.find("/non-US/") != string::npos) - Res += 2; + Res += 20; if (Path.find("/source/") != string::npos) - Res += 1; + Res += 10; + if (Path.find("/debian/") != string::npos) + Res -= 10; return Res; } /*}}}*/ @@ -250,7 +256,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()); @@ -264,8 +270,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.. @@ -276,6 +283,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; @@ -353,7 +362,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 | ios::nocreate); if (!F != 0) return _error->Errno("ifstream::ifstream","Opening %s",File.c_str()); @@ -365,7 +375,8 @@ bool WriteSourceList(string Name,vector &List,bool Source) "Failed to open %s.new",File.c_str()); // Create a short uri without the path - string ShortURI = "cdrom:" + Name + "/"; + string ShortURI = "cdrom:[" + Name + "]/"; + string ShortURI2 = "cdrom:" + Name + "/"; // For Compatibility const char *Type; if (Source == true) @@ -397,8 +408,8 @@ bool WriteSourceList(string Name,vector &List,bool Source) string::size_type Space = (*I).find(' '); if (Space == string::npos) return _error->Error("Internal error"); - Out << Type << " \"cdrom:" << Name << "/" << string(*I,0,Space) << - "\" " << string(*I,Space+1) << endl; + Out << Type << " cdrom:[" << Name << "]/" << string(*I,0,Space) << + " " << string(*I,Space+1) << endl; } } First = false; @@ -415,7 +426,8 @@ bool WriteSourceList(string Name,vector &List,bool Source) } // Emit lines like this one - if (cType != Type || string(URI,0,ShortURI.length()) != ShortURI) + if (cType != Type || (string(URI,0,ShortURI.length()) != ShortURI && + string(URI,0,ShortURI.length()) != ShortURI2)) { Out << Buffer << endl; continue; @@ -431,8 +443,8 @@ bool WriteSourceList(string Name,vector &List,bool Source) if (Space == string::npos) return _error->Error("Internal error"); - Out << "deb \"cdrom:" << Name << "/" << string(*I,0,Space) << - "\" " << string(*I,Space+1) << endl; + Out << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) << + " " << string(*I,Space+1) << endl; } } @@ -537,11 +549,12 @@ bool DoAdd(CommandLine &) if (_config->FindB("Debug::aptcdrom",false) == true) { - cout << "I found:" << endl; + cout << "I found (binary):" << endl; for (vector::iterator I = List.begin(); I != List.end(); I++) - { cout << *I << endl; - } + cout << "I found (source):" << endl; + for (vector::iterator I = sList.begin(); I != sList.end(); I++) + cout << *I << endl; } // Fix up the list @@ -551,7 +564,7 @@ bool DoAdd(CommandLine &) cout << "Found " << List.size() << " package indexes and " << sList.size() << " source indexes." << endl; - if (List.size() == 0) + if (List.size() == 0 && sList.size() == 0) return _error->Error("Unable to locate any package files, perhaps this is not a Debian Disc"); // Check if the CD is in the database @@ -569,6 +582,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); } @@ -583,8 +602,8 @@ bool DoAdd(CommandLine &) Name = PromptLine(""); if (Name.empty() == false && Name.find('"') == string::npos && - Name.find(':') == string::npos && - Name.find('/') == string::npos) + Name.find('[') == string::npos && + Name.find(']') == string::npos) break; cout << "That is not a valid name, try again " << endl; } @@ -592,14 +611,15 @@ bool DoAdd(CommandLine &) } else Name = Database.Find("CD::" + ID); - + + // Escape special characters string::iterator J = Name.begin(); for (; J != Name.end(); J++) - if (*J == '/' || *J == '"' || *J == ':') + if (*J == '"' || *J == ']' || *J == '[') *J = '_'; Database.Set("CD::" + ID,Name); - cout << "This Disc is called '" << Name << "'" << endl; + cout << "This Disc is called:" << endl << " '" << Name << "'" << endl; // Copy the package files to the state directory PackageCopy Copy; @@ -631,8 +651,8 @@ bool DoAdd(CommandLine &) if (Space == string::npos) return _error->Error("Internal error"); - cout << "deb \"cdrom:" << Name << "/" << string(*I,0,Space) << - "\" " << string(*I,Space+1) << endl; + cout << "deb cdrom:[" << Name << "]/" << string(*I,0,Space) << + " " << string(*I,Space+1) << endl; } for (vector::iterator I = sList.begin(); I != sList.end(); I++) @@ -641,11 +661,55 @@ bool DoAdd(CommandLine &) if (Space == string::npos) return _error->Error("Internal error"); - cout << "deb-src \"cdrom:" << Name << "/" << string(*I,0,Space) << - "\" " << string(*I,Space+1) << endl; + cout << "deb-src cdrom:[" << Name << "]/" << string(*I,0,Space) << + " " << string(*I,Space+1) << endl; } cout << "Repeat this process for the rest of the CDs in your set." << endl; + + // Unmount and finish + if (_config->FindB("APT::CDROM::NoMount",false) == false) + UnmountCdrom(CDROM); + + 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; } /*}}}*/ @@ -655,31 +719,33 @@ bool DoAdd(CommandLine &) /* */ 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; } /*}}}*/ @@ -701,19 +767,21 @@ int main(int argc,const char *argv[]) {0,0,0,0}}; CommandLine::Dispatch Cmds[] = { {"add",&DoAdd}, + {"ident",&DoIdent}, {0,0}}; // 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; } // See if the help should be shown - if (_config->FindB("help") == true || + if (_config->FindB("help") == true || _config->FindB("version") == true || CmdL.FileSize() == 0) return ShowHelp();