// -*- 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.43 2003/04/26 23:26:13 doogie Exp $
/* ######################################################################
APT CDROM - Tool for handling APT's CDROM database.
#include <apt-pkg/init.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/progress.h>
-#include <apt-pkg/tagfile.h>
#include <apt-pkg/cdromutl.h>
#include <apt-pkg/strutl.h>
#include <config.h>
+#include <apti18n.h>
+
+#include "indexcopy.h"
+#include <locale.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <stdio.h>
/*}}}*/
+using namespace std;
+
// FindPackages - Find the package files on the CDROM /*{{{*/
// ---------------------------------------------------------------------
/* We look over the cdrom for package files. This is a recursive
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<string> &List, unsigned int Depth = 0)
+bool FindPackages(string CD,vector<string> &List,vector<string> &SList,
+ string &InfoDir,unsigned int Depth = 0)
{
static ino_t Inodes[9];
if (Depth >= 7)
if (CD[CD.length()-1] != '/')
CD += '/';
-
+
if (chdir(CD.c_str()) != 0)
return _error->Errno("chdir","Unable to change to %s",CD.c_str());
+ // Look for a .disk subdirectory
+ struct stat Buf;
+ if (stat(".disk",&Buf) == 0)
+ {
+ if (InfoDir.empty() == true)
+ 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 */
- struct stat Buf;
- if (stat("Packages",&Buf) == 0)
+ if (stat("Packages",&Buf) == 0 || stat("Packages.gz",&Buf) == 0)
{
List.push_back(CD);
if (_config->FindB("APT::CDROM::Thorough",false) == false)
return true;
}
-
+ if (stat("Sources.gz",&Buf) == 0 || stat("Sources",&Buf) == 0)
+ {
+ SList.push_back(CD);
+
+ // Continue down if thorough is given
+ if (_config->FindB("APT::CDROM::Thorough",false) == false)
+ return true;
+ }
+
DIR *D = opendir(".");
if (D == 0)
return _error->Errno("opendir","Unable to read %s",CD.c_str());
// Skip some files..
if (strcmp(Dir->d_name,".") == 0 ||
strcmp(Dir->d_name,"..") == 0 ||
- strcmp(Dir->d_name,"source") == 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;
Inodes[Depth] = Buf.st_ino;
// Descend
- if (FindPackages(CD + Dir->d_name,List,Depth+1) == false)
+ if (FindPackages(CD + Dir->d_name,List,SList,InfoDir,Depth+1) == false)
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);
bool DropBinaryArch(vector<string> &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++)
{
// 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)
{
int Res = 0;
if (Path.find("stable/") != string::npos)
- Res += 2;
+ Res += 29;
if (Path.find("/binary-") != string::npos)
- Res += 2;
- if (Path.find("frozen/") != string::npos)
- Res += 2;
+ Res += 20;
+ if (Path.find("testing/") != string::npos)
+ 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 += 10;
+ if (Path.find("/debian/") != string::npos)
+ Res -= 10;
return Res;
}
/*}}}*/
// DropRepeats - Drop repeated files resulting from symlinks /*{{{*/
// ---------------------------------------------------------------------
/* Here we go and stat every file that we found and strip dup inodes. */
-bool DropRepeats(vector<string> &List)
+bool DropRepeats(vector<string> &List,const char *Name)
{
// Get a list of all the inodes
ino_t *Inodes = new ino_t[List.size()];
for (unsigned int I = 0; I != List.size(); I++)
{
struct stat Buf;
- if (stat((List[I] + "Packages").c_str(),&Buf) != 0)
- _error->Errno("stat","Failed to stat %sPackages",List[I].c_str());
+ if (stat((List[I] + Name).c_str(),&Buf) != 0 &&
+ stat((List[I] + Name + ".gz").c_str(),&Buf) != 0)
+ _error->Errno("stat","Failed to stat %s%s",List[I].c_str(),
+ Name);
Inodes[I] = Buf.st_ino;
}
return true;
}
/*}}}*/
-// ConvertToSourceList - Convert a Path to a sourcelist entry /*{{{*/
-// ---------------------------------------------------------------------
-/* We look for things in dists/ notation and convert them to
- <dist> <component> form otherwise it is left alone. This also strips
- the CD path. */
-void ConvertToSourceList(string CD,string &Path)
-{
- char S[300];
- sprintf(S,"binary-%s",_config->Find("Apt::Architecture").c_str());
-
- // Strip the cdrom base path
- Path = string(Path,CD.length());
- if (Path.empty() == true)
- Path = "/";
-
- // Too short to be a dists/ type
- if (Path.length() < strlen("dists/"))
- return;
-
- // Not a dists type.
- if (stringcmp(Path.begin(),Path.begin()+strlen("dists/"),"dists/") != 0)
- return;
-
- // Isolate the dist
- string::size_type Slash = strlen("dists/");
- string::size_type Slash2 = Path.find('/',Slash + 1);
- if (Slash2 == string::npos || Slash2 + 2 >= Path.length())
- return;
- string Dist = string(Path,Slash,Slash2 - Slash);
-
- // Isolate the component
- Slash = Path.find('/',Slash2+1);
- if (Slash == string::npos || Slash + 2 >= Path.length())
- return;
- string Comp = string(Path,Slash2+1,Slash - Slash2-1);
-
- // Verify the trailing binar - bit
- Slash2 = Path.find('/',Slash + 1);
- if (Slash == string::npos)
- return;
- string Binary = string(Path,Slash+1,Slash2 - Slash-1);
-
- if (Binary != S)
- return;
-
- Path = Dist + ' ' + Comp;
-}
- /*}}}*/
-// GrabFirst - Return the first Depth path components /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool GrabFirst(string Path,string &To,unsigned int Depth)
-{
- string::size_type I = 0;
- do
- {
- I = Path.find('/',I+1);
- Depth--;
- }
- while (I != string::npos && Depth != 0);
-
- if (I == string::npos)
- return false;
-
- To = string(Path,0,I+1);
- return true;
-}
- /*}}}*/
-// ChopDirs - Chop off the leading directory components /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-string ChopDirs(string Path,unsigned int Depth)
-{
- string::size_type I = 0;
- do
- {
- I = Path.find('/',I+1);
- Depth--;
- }
- while (I != string::npos && Depth != 0);
-
- if (I == string::npos)
- return string();
-
- return string(Path,I+1);
-}
- /*}}}*/
-// ReconstructPrefix - Fix strange prefixing /*{{{*/
-// ---------------------------------------------------------------------
-/* This prepends dir components from the path to the package files to
- the path to the deb until it is found */
-bool ReconstructPrefix(string &Prefix,string OrigPath,string CD,
- string File)
-{
- bool Debug = _config->FindB("Debug::aptcdrom",false);
- unsigned int Depth = 1;
- string MyPrefix = Prefix;
- while (1)
- {
- struct stat Buf;
- if (stat(string(CD + MyPrefix + File).c_str(),&Buf) != 0)
- {
- if (Debug == true)
- cout << "Failed, " << CD + MyPrefix + File << endl;
- if (GrabFirst(OrigPath,MyPrefix,Depth++) == true)
- continue;
-
- return false;
- }
- else
- {
- Prefix = MyPrefix;
- return true;
- }
- }
- return false;
-}
- /*}}}*/
-// ReconstructChop - Fixes bad source paths /*{{{*/
-// ---------------------------------------------------------------------
-/* This removes path components from the filename and prepends the location
- of the package files until a file is found */
-bool ReconstructChop(unsigned long &Chop,string Dir,string File)
-{
- // Attempt to reconstruct the filename
- unsigned long Depth = 0;
- while (1)
- {
- struct stat Buf;
- if (stat(string(Dir + File).c_str(),&Buf) != 0)
- {
- File = ChopDirs(File,1);
- Depth++;
- if (File.empty() == false)
- continue;
- return false;
- }
- else
- {
- Chop = Depth;
- return true;
- }
- }
- return false;
-}
- /*}}}*/
-
-// CopyPackages - Copy the package files from the CD /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool CopyPackages(string CDROM,string Name,vector<string> &List)
-{
- OpTextProgress Progress;
-
- bool NoStat = _config->FindB("APT::CDROM::Fast",false);
- bool Debug = _config->FindB("Debug::aptcdrom",false);
-
- // Prepare the progress indicator
- unsigned long TotalSize = 0;
- for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
- {
- struct stat Buf;
- if (stat(string(*I + "Packages").c_str(),&Buf) != 0)
- return _error->Errno("stat","Stat failed for %s",
- string(*I + "Packages").c_str());
- TotalSize += Buf.st_size;
- }
-
- unsigned long CurrentSize = 0;
- unsigned int NotFound = 0;
- unsigned int WrongSize = 0;
- unsigned int Packages = 0;
- for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
- {
- string OrigPath = string(*I,CDROM.length());
-
- // Open the package file
- FileFd Pkg(*I + "Packages",FileFd::ReadOnly);
- pkgTagFile Parser(Pkg);
- if (_error->PendingError() == true)
- return false;
-
- // Open the output file
- char S[400];
- sprintf(S,"cdrom:%s/%sPackages",Name.c_str(),(*I).c_str() + CDROM.length());
- string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
- TargetF += URItoFileName(S);
- if (_config->FindB("APT::CDROM::NoAct",false) == true)
- TargetF = "/dev/null";
- FileFd Target(TargetF,FileFd::WriteEmpty);
- if (_error->PendingError() == true)
- return false;
-
- // Setup the progress meter
- Progress.OverallProgress(CurrentSize,TotalSize,Pkg.Size(),
- "Reading Package Lists");
-
- // Parse
- Progress.SubProgress(Pkg.Size());
- pkgTagSection Section;
- string Prefix;
- unsigned long Hits = 0;
- unsigned long Chop = 0;
- while (Parser.Step(Section) == true)
- {
- Progress.Progress(Parser.Offset());
-
- string File = Section.FindS("Filename");
- unsigned long Size = Section.FindI("Size");
- if (File.empty() || Size == 0)
- return _error->Error("Cannot find filename or size tag");
-
- if (Chop != 0)
- File = OrigPath + ChopDirs(File,Chop);
-
- // See if the file exists
- if (NoStat == false || Hits < 10)
- {
- // Attempt to fix broken structure
- if (Hits == 0)
- {
- if (ReconstructPrefix(Prefix,OrigPath,CDROM,File) == false &&
- ReconstructChop(Chop,*I,File) == false)
- {
- NotFound++;
- continue;
- }
- if (Chop != 0)
- File = OrigPath + ChopDirs(File,Chop);
- }
-
- // Get the size
- struct stat Buf;
- if (stat(string(CDROM + Prefix + File).c_str(),&Buf) != 0)
- {
- NotFound++;
- continue;
- }
-
- // Size match
- if ((unsigned)Buf.st_size != Size)
- {
- WrongSize++;
- continue;
- }
- }
-
- Packages++;
- Hits++;
-
- // Copy it to the target package file
- const char *Start;
- const char *Stop;
- if (Chop != 0)
- {
- // Mangle the output filename
- const char *Filename;
- Section.Find("Filename",Filename,Stop);
-
- /* We need to rewrite the filename field so we emit
- all fields except the filename file and rewrite that one */
- for (unsigned int I = 0; I != Section.Count(); I++)
- {
- Section.Get(Start,Stop,I);
- if (Start <= Filename && Stop > Filename)
- {
- char S[500];
- sprintf(S,"Filename: %s\n",File.c_str());
- if (I + 1 == Section.Count())
- strcat(S,"\n");
- if (Target.Write(S,strlen(S)) == false)
- return false;
- }
- else
- if (Target.Write(Start,Stop-Start) == false)
- return false;
- }
- if (Target.Write("\n",1) == false)
- return false;
- }
- else
- {
- Section.GetSection(Start,Stop);
- if (Target.Write(Start,Stop-Start) == false)
- return false;
- }
- }
-
- if (Debug == true)
- cout << " Processed by using Prefix '" << Prefix << "' and chop " << Chop << endl;
-
- if (_config->FindB("APT::CDROM::NoAct",false) == false)
- {
- // Move out of the partial directory
- Target.Close();
- string FinalF = _config->FindDir("Dir::State::lists");
- FinalF += URItoFileName(S);
- if (rename(TargetF.c_str(),FinalF.c_str()) != 0)
- return _error->Errno("rename","Failed to rename");
-
- // Copy the release file
- sprintf(S,"cdrom:%s/%sRelease",Name.c_str(),(*I).c_str() + CDROM.length());
- string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
- TargetF += URItoFileName(S);
- if (FileExists(*I + "Release") == true)
- {
- FileFd Target(TargetF,FileFd::WriteEmpty);
- FileFd Rel(*I + "Release",FileFd::ReadOnly);
- if (_error->PendingError() == true)
- return false;
-
- if (CopyFile(Rel,Target) == false)
- return false;
- }
- else
- {
- // Empty release file
- FileFd Target(TargetF,FileFd::WriteEmpty);
- }
-
- // Rename the release file
- FinalF = _config->FindDir("Dir::State::lists");
- FinalF += URItoFileName(S);
- if (rename(TargetF.c_str(),FinalF.c_str()) != 0)
- return _error->Errno("rename","Failed to rename");
- }
-
- /* Mangle the source to be in the proper notation with
- prefix dist [component] */
- *I = string(*I,Prefix.length());
- ConvertToSourceList(CDROM,*I);
- *I = Prefix + ' ' + *I;
-
- CurrentSize += Pkg.Size();
- }
- Progress.Done();
-
- // Some stats
- cout << "Wrote " << Packages << " package records" ;
- if (NotFound != 0)
- cout << " with " << NotFound << " missing files";
- if (NotFound != 0 && WrongSize != 0)
- cout << " and";
- if (WrongSize != 0)
- cout << " with " << WrongSize << " mismatched files";
- cout << '.' << endl;
-
- if (Packages == 0)
- return _error->Error("No valid package records were found.");
-
- if (NotFound + WrongSize > 10)
- cout << "Alot of package entires were discarded, perhaps this CD is funny?" << endl;
-
- return true;
-}
- /*}}}*/
// ReduceSourceList - Takes the path list and reduces it /*{{{*/
// ---------------------------------------------------------------------
/* 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<string> &List)
+void ReduceSourcelist(string CD,vector<string> &List)
{
sort(List.begin(),List.end());
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<string>::iterator J = List.begin(); J != I; J++)
{
// Find a space..
if (SSpace2 == string::npos)
continue;
+ if (string(*J,0,Space2) != Prefix)
+ continue;
if (string(*J,Space2,SSpace2-Space2) != Word1)
continue;
appends the new CDROM entires just after the first block of comments.
This places them first in the file. It also removes any old entries
that were the same. */
-bool WriteSourceList(string Name,vector<string> &List)
+bool WriteSourceList(string Name,vector<string> &List,bool Source)
{
+ if (List.size() == 0)
+ return true;
+
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());
"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)
+ Type = "deb-src";
+ else
+ Type = "deb";
char Buffer[300];
int CurLine = 0;
string::size_type Space = (*I).find(' ');
if (Space == string::npos)
return _error->Error("Internal error");
-
- Out << "deb \"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;
// Grok it
- string Type;
+ string cType;
string URI;
- char *C = Buffer;
- if (ParseQuoteWord(C,Type) == false ||
+ const char *C = Buffer;
+ if (ParseQuoteWord(C,cType) == false ||
ParseQuoteWord(C,URI) == false)
{
Out << Buffer << endl;
}
// Emit lines like this one
- if (Type != "deb" || 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;
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;
}
}
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
cout << "Scanning Disc for index files.. " << flush;
// Get the CD structure
vector<string> List;
+ vector<string> sList;
string StartDir = SafeGetCWD();
- if (FindPackages(CDROM,List) == false)
+ string InfoDir;
+ if (FindPackages(CDROM,List,sList,InfoDir) == false)
{
cout << endl;
return false;
if (_config->FindB("Debug::aptcdrom",false) == true)
{
- cout << "I found:" << endl;
+ cout << "I found (binary):" << endl;
for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
- {
cout << *I << endl;
- }
+ cout << "I found (source):" << endl;
+ for (vector<string>::iterator I = sList.begin(); I != sList.end(); I++)
+ cout << *I << endl;
}
// Fix up the list
DropBinaryArch(List);
- DropRepeats(List);
- cout << "Found " << List.size() << " package index files." << endl;
+ DropRepeats(List,"Packages");
+ DropRepeats(sList,"Sources");
+ 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
_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);
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);
}
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;
}
}
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
- if (CopyPackages(CDROM,Name,List) == false)
+ PackageCopy Copy;
+ SourceCopy SrcCopy;
+ if (Copy.CopyPackages(CDROM,Name,List) == false ||
+ SrcCopy.CopyPackages(CDROM,Name,sList) == false)
return false;
ReduceSourcelist(CDROM,List);
+ ReduceSourcelist(CDROM,sList);
// Write the database and sourcelist
if (_config->FindB("APT::cdrom::NoAct",false) == false)
return false;
cout << "Writing new source list" << endl;
- if (WriteSourceList(Name,List) == false)
+ if (WriteSourceList(Name,List,false) == false ||
+ WriteSourceList(Name,sList,true) == false)
return false;
}
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<string>::iterator I = sList.begin(); I != sList.end(); I++)
+ {
+ string::size_type Space = (*I).find(' ');
+ if (Space == string::npos)
+ return _error->Error("Internal error");
+
+ 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;
}
/*}}}*/
/* */
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;
}
/*}}}*/
{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;
}
// 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();