X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/9bf3ee5c03b464f6396868c3829c5b852b8c5fbb..8229745799aeb137eb18144eda7a7a33ca11a933:/cmdline/apt-cdrom.cc?ds=sidebyside diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 7875b1444..e1847be6e 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.9 1998/12/09 00:11:50 jgg Exp $ +// $Id: apt-cdrom.cc,v 1.22 1999/04/07 06:00:20 jgg Exp $ /* ###################################################################### APT CDROM - Tool for handling APT's CDROM database. @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -38,8 +38,10 @@ search that short circuits when it his a package file in the dir. This speeds it up greatly as the majority of the size is in the binary-* sub dirs. */ -bool FindPackages(string CD,vector &List, int Depth = 0) +bool FindPackages(string CD,vector &List,string &InfoDir, + unsigned int Depth = 0) { + static ino_t Inodes[9]; if (Depth >= 7) return true; @@ -53,8 +55,7 @@ bool FindPackages(string CD,vector &List, int Depth = 0) this dir is controlled by those package files so we don't look down anymore */ struct stat Buf; - if (stat("Packages",&Buf) == 0 || - stat("Packages.gz",&Buf) == 0) + if (stat("Packages",&Buf) == 0) { List.push_back(CD); @@ -63,7 +64,13 @@ bool FindPackages(string CD,vector &List, int Depth = 0) return true; } - bool Thorough = _config->FindB("APT::CDROM::Thorough",false); + // Look for a .disk subdirectory + if (stat(".disk",&Buf) == 0) + { + if (InfoDir.empty() == true) + InfoDir = CD + ".disk/"; + } + DIR *D = opendir("."); if (D == 0) return _error->Errno("opendir","Unable to read %s",CD.c_str()); @@ -87,11 +94,18 @@ bool FindPackages(string CD,vector &List, int Depth = 0) if (S_ISDIR(Buf.st_mode) == 0) continue; - if (Thorough == false && S_ISLNK(Buf.st_mode) != 0) + unsigned int I; + for (I = 0; I != Depth; I++) + if (Inodes[I] == Buf.st_ino) + break; + if (I != Depth) continue; + // Store the inodes weve seen + Inodes[Depth] = Buf.st_ino; + // Descend - if (FindPackages(CD + Dir->d_name,List,Depth+1) == false) + if (FindPackages(CD + Dir->d_name,List,InfoDir,Depth+1) == false) break; if (chdir(CD.c_str()) != 0) @@ -149,6 +163,8 @@ int Score(string Path) int Res = 0; if (Path.find("stable/") != string::npos) Res += 2; + if (Path.find("/binary-") != string::npos) + Res += 2; if (Path.find("frozen/") != string::npos) Res += 2; if (Path.find("/dists/") != string::npos) @@ -174,11 +190,14 @@ bool DropRepeats(vector &List) for (unsigned int I = 0; I != List.size(); I++) { struct stat Buf; - if (stat(List[I].c_str(),&Buf) != 0) - _error->Errno("stat","Failed to stat %s",List[I].c_str()); + if (stat((List[I] + "Packages").c_str(),&Buf) != 0) + _error->Errno("stat","Failed to stat %sPackages",List[I].c_str()); Inodes[I] = Buf.st_ino; } + if (_error->PendingError() == true) + return false; + // Look for dups for (unsigned int I = 0; I != List.size(); I++) { @@ -820,13 +839,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 @@ -844,7 +860,8 @@ bool DoAdd(CommandLine &) // Get the CD structure vector List; string StartDir = SafeGetCWD(); - if (FindPackages(CDROM,List) == false) + string InfoDir; + if (FindPackages(CDROM,List,InfoDir) == false) { cout << endl; return false; @@ -875,9 +892,10 @@ bool DoAdd(CommandLine &) _config->FindB("APT::CDROM::Rename",false) == true) { // Try to use the CDs label if at all possible - if (FileExists(CDROM + "/.disk/info") == true) + if (InfoDir.empty() == false && + FileExists(InfoDir + "/info") == true) { - ifstream F(string(CDROM+ "/.disk/info").c_str()); + ifstream F(string(InfoDir + "/info").c_str()); if (!F == 0) getline(F,Name); @@ -896,15 +914,22 @@ bool DoAdd(CommandLine &) { Name = PromptLine(""); if (Name.empty() == false && + Name.find('"') == string::npos && + Name.find(':') == string::npos && Name.find('/') == string::npos) break; cout << "That is not a valid name, try again " << endl; - } - + } } } else Name = Database.Find("CD::" + ID); + + string::iterator J = Name.begin(); + for (; J != Name.end(); J++) + if (*J == '/' || *J == '"' || *J == ':') + *J = '_'; + Database.Set("CD::" + ID,Name); cout << "This Disc is called '" << Name << "'" << endl; @@ -926,7 +951,7 @@ bool DoAdd(CommandLine &) } // Print the sourcelist entries - cout << "Source List entires for this Disc are:" << endl; + cout << "Source List entries for this Disc are:" << endl; for (vector::iterator I = List.begin(); I != List.end(); I++) { string::size_type Space = (*I).find(' '); @@ -948,6 +973,8 @@ int ShowHelp() { cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE << " compiled on " << __DATE__ << " " << __TIME__ << endl; + if (_config->FindB("version") == true) + return 100; cout << "Usage: apt-cdrom [options] command" << endl; cout << endl; @@ -966,7 +993,7 @@ int ShowHelp() 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, ie -o dir::cache=/tmp" << endl; + cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl; cout << "See fstab(5)" << endl; return 100; } @@ -976,6 +1003,7 @@ int main(int argc,const char *argv[]) { CommandLine::Args Args[] = { {'h',"help","help",0}, + {'v',"version","version",0}, {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg}, {'r',"rename","APT::CDROM::Rename",0}, {'m',"no-mount","APT::CDROM::NoMount",0}, @@ -1004,6 +1032,10 @@ int main(int argc,const char *argv[]) if (_config->FindB("help") == true || CmdL.FileSize() == 0) return ShowHelp(); + + // Deal with stdout not being a tty + if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1) + _config->Set("quiet","1"); // Match the operation CmdL.DispatchArg(Cmds);