diff options
author | Arch Librarian <arch@canonical.com> | 2004-09-20 16:54:16 +0000 |
---|---|---|
committer | Arch Librarian <arch@canonical.com> | 2004-09-20 16:54:16 +0000 |
commit | 13d87e2e0f84512bc139637635b1e5025fa82a6c (patch) | |
tree | aa40b4ff29cde5f7e937a238284a8abb337ce582 | |
parent | d64663d4456b9b755af220a511de98c6d4bd4af3 (diff) |
Added an open function
Author: jgg
Date: 1999-07-11 22:42:32 GMT
Added an open function
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 18 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 9 | ||||
-rw-r--r-- | cmdline/apt-cdrom.cc | 45 |
3 files changed, 50 insertions, 22 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 43717da16..4374dd7d5 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1,6 +1,6 @@ // -*- 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 @@ -250,11 +250,12 @@ int ExecFork() } /*}}}*/ -// 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) { @@ -281,12 +282,11 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms) } 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 /*{{{*/ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 8a1083241..e24f9cfb6 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -1,6 +1,6 @@ // -*- 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 @@ -45,6 +45,7 @@ class FileFd 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 @@ -56,7 +57,11 @@ class FileFd 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(); diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 67c3bc7e4..88f1da102 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.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. @@ -38,8 +38,8 @@ 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) @@ -70,6 +70,14 @@ bool FindPackages(string CD,vector<string> &List,string &InfoDir, 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) @@ -81,7 +89,7 @@ bool FindPackages(string CD,vector<string> &List,string &InfoDir, // 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; @@ -105,7 +113,7 @@ bool FindPackages(string CD,vector<string> &List,string &InfoDir, 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) @@ -183,15 +191,16 @@ int Score(string Path) // 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; } @@ -886,9 +895,10 @@ bool DoAdd(CommandLine &) 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; @@ -907,8 +917,10 @@ bool DoAdd(CommandLine &) // 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"); @@ -965,6 +977,7 @@ bool DoAdd(CommandLine &) return false; ReduceSourcelist(CDROM,List); + ReduceSourcelist(CDROM,sList); // Write the database and sourcelist if (_config->FindB("APT::cdrom::NoAct",false) == false) @@ -989,6 +1002,16 @@ bool DoAdd(CommandLine &) "\" " << 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; } |