// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.27 1999/04/20 05:02:09 jgg Exp $
+// $Id: fileutl.cc,v 1.28 1999/07/11 22:42:32 jgg Exp $
/* ######################################################################
File Utilities
}
/*}}}*/
-// FileFd::FileFd - Open a file /*{{{*/
+// FileFd::Open - Open a file /*{{{*/
// ---------------------------------------------------------------------
/* The most commonly used open mode combinations are given with Mode */
-FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms)
+bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms)
{
+ Close();
Flags = AutoClose;
switch (Mode)
{
}
if (iFd < 0)
- _error->Errno("open","Could not open file %s",FileName.c_str());
- else
- {
- this->FileName = FileName;
- SetCloseExec(iFd,true);
- }
+ return _error->Errno("open","Could not open file %s",FileName.c_str());
+
+ this->FileName = FileName;
+ SetCloseExec(iFd,true);
+ return true;
}
/*}}}*/
// FileFd::~File - Closes the file /*{{{*/
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.h,v 1.18 1999/04/20 05:02:09 jgg Exp $
+// $Id: fileutl.h,v 1.19 1999/07/11 22:42:32 jgg Exp $
/* ######################################################################
File Utilities
bool Truncate(unsigned long To);
unsigned long Tell();
unsigned long Size();
+ bool Open(string FileName,OpenMode Mode,unsigned long Perms = 0666);
bool Close();
// Simple manipulators
inline void OpFail() {Flags |= Fail;};
inline string &Name() {return FileName;};
- FileFd(string FileName,OpenMode Mode,unsigned long Perms = 0666);
+ FileFd(string FileName,OpenMode Mode,unsigned long Perms = 0666) : iFd(-1),
+ Flags(0)
+ {
+ Open(FileName,Mode,Perms);
+ };
FileFd(int Fd = -1) : iFd(Fd), Flags(AutoClose) {};
FileFd(int Fd,bool) : iFd(Fd), Flags(0) {};
virtual ~FileFd();
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: apt-cdrom.cc,v 1.26 1999/07/03 03:10:35 jgg Exp $
+// $Id: apt-cdrom.cc,v 1.27 1999/07/11 22:42:32 jgg Exp $
/* ######################################################################
APT CDROM - Tool for handling APT's CDROM database.
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,string &InfoDir,
- 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 (_config->FindB("APT::CDROM::Thorough",false) == false)
return true;
}
+ if (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)
// 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,"experimental") == 0 ||
strcmp(Dir->d_name,"binary-all") == 0)
continue;
Inodes[Depth] = Buf.st_ino;
// Descend
- if (FindPackages(CD + Dir->d_name,List,InfoDir,Depth+1) == false)
+ if (FindPackages(CD + Dir->d_name,List,SList,InfoDir,Depth+1) == false)
break;
if (chdir(CD.c_str()) != 0)
// 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)
+ _error->Errno("stat","Failed to stat %s%s",List[I].c_str(),
+ Name);
Inodes[I] = Buf.st_ino;
}
cout << "Scanning Disc for index files.. " << flush;
// Get the CD structure
vector<string> List;
+ vector<string> sList;
string StartDir = SafeGetCWD();
string InfoDir;
- if (FindPackages(CDROM,List,InfoDir) == false)
+ if (FindPackages(CDROM,List,sList,InfoDir) == false)
{
cout << endl;
return false;
// 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)
return _error->Error("Unable to locate any package files, perhaps this is not a Debian Disc");
return false;
ReduceSourcelist(CDROM,List);
+ ReduceSourcelist(CDROM,sList);
// Write the database and sourcelist
if (_config->FindB("APT::cdrom::NoAct",false) == false)
"\" " << 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;
return true;
}