-// 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,vector<string> &SList,
- string &InfoDir,unsigned int Depth = 0)
-{
- static ino_t Inodes[9];
- if (Depth >= 7)
- return true;
-
- 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/";
- }
-
- /* 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 */
- if (stat("Packages",&Buf) == 0)
- {
- List.push_back(CD);
-
- // Continue down if thorough is given
- 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());
-
- // Run over the directory
- for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
- {
- // Skip some files..
- if (strcmp(Dir->d_name,".") == 0 ||
- strcmp(Dir->d_name,"..") == 0 ||
- //strcmp(Dir->d_name,"source") == 0 ||
- strcmp(Dir->d_name,"experimental") == 0 ||
- strcmp(Dir->d_name,"binary-all") == 0)
- continue;
-
- // See if the name is a sub directory
- struct stat Buf;
- if (stat(Dir->d_name,&Buf) != 0)
- continue;
-
- if (S_ISDIR(Buf.st_mode) == 0)
- continue;
-
- 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,SList,InfoDir,Depth+1) == false)
- break;