using namespace std;
-// DecompressFile - wrapper for decompressing compressed files /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool DecompressFile(string Filename, int *fd, off_t *FileSize)
-{
- struct stat Buf;
- *fd = -1;
-
- std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
- std::vector<APT::Configuration::Compressor>::const_iterator UnCompress;
- std::string file = std::string(Filename).append(UnCompress->Extension);
- for (UnCompress = compressor.begin(); UnCompress != compressor.end(); ++UnCompress)
- {
- if (stat(file.c_str(), &Buf) == 0)
- break;
- }
-
- if (UnCompress == compressor.end())
- return _error->Errno("decompressor", "Unable to parse file");
-
- *FileSize = Buf.st_size;
-
- // Create a data pipe
- int Pipe[2] = {-1,-1};
- if (pipe(Pipe) != 0)
- return _error->Errno("pipe",_("Failed to create subprocess IPC"));
- for (int J = 0; J != 2; J++)
- SetCloseExec(Pipe[J],true);
-
- *fd = Pipe[1];
-
- // The child..
- pid_t Pid = ExecFork();
- if (Pid == 0)
- {
- dup2(Pipe[1],STDOUT_FILENO);
- SetCloseExec(STDOUT_FILENO, false);
-
- std::vector<char const*> Args;
- Args.push_back(UnCompress->Binary.c_str());
- for (std::vector<std::string>::const_iterator a = UnCompress->UncompressArgs.begin();
- a != UnCompress->UncompressArgs.end(); ++a)
- Args.push_back(a->c_str());
- Args.push_back("--stdout");
- Args.push_back(file.c_str());
- Args.push_back(NULL);
-
- execvp(Args[0],(char **)&Args[0]);
- cerr << _("Failed to exec compressor ") << Args[0] << endl;
- _exit(100);
- }
-
- // Wait for decompress to finish
- if (ExecWait(Pid, UnCompress->Binary.c_str(), false) == false)
- return false;
-
- return true;
-}
- /*}}}*/
// IndexCopy::CopyPackages - Copy the package files from the CD /*{{{*/
// ---------------------------------------------------------------------
/* */
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
string OrigPath = string(*I,CDROM.length());
- off_t FileSize = 0;
// Open the package file
- FileFd Pkg;
- if (RealFileExists(*I + GetFileName()) == true)
- {
- Pkg.Open(*I + GetFileName(),FileFd::ReadOnly);
- FileSize = Pkg.Size();
- }
- else
- {
- int fd;
- if (!DecompressFile(string(*I + GetFileName()), &fd, &FileSize))
- return _error->Errno("decompress","Decompress failed for %s",
- string(*I + GetFileName()).c_str());
- Pkg.Fd(dup(fd));
- Pkg.Seek(0);
- }
+ FileFd Pkg(*I + GetFileName(), FileFd::ReadOnly, FileFd::Auto);
+ off_t const FileSize = Pkg.Size();
pkgTagFile Parser(&Pkg);
if (_error->PendingError() == true)
*/
void IndexCopy::ConvertToSourceList(string CD,string &Path)
{
- char S[300];
- snprintf(S,sizeof(S),"binary-%s",_config->Find("Apt::Architecture").c_str());
-
// Strip the cdrom base path
Path = string(Path,CD.length());
if (Path.empty() == true)
return;
string Binary = string(Path,Slash+1,BinSlash - Slash-1);
- if (Binary != S && Binary != "source")
+ if (strncmp(Binary.c_str(), "binary-", strlen("binary-")) == 0)
+ {
+ Binary.erase(0, strlen("binary-"));
+ if (APT::Configuration::checkArchitecture(Binary) == false)
+ continue;
+ }
+ else if (Binary != "source")
continue;
Path = Dist + ' ' + Comp;
bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex)
{
const indexRecords::checkSum *Record = MetaIndex->Lookup(file);
+ bool const Debug = _config->FindB("Debug::aptcdrom",false);
- // we skip non-existing files in the verifcation to support a cdrom
- // with no Packages file (just a Package.gz), see LP: #255545
- // (non-existing files are not considered a error)
+ // we skip non-existing files in the verifcation of the Release file
+ // as non-existing files do not harm, but a warning scares people and
+ // makes it hard to strip unneeded files from an ISO like uncompressed
+ // indexes as it is done on the mirrors (see also LP: #255545 )
if(!RealFileExists(prefix+file))
{
- _error->Warning(_("Skipping nonexistent file %s"), string(prefix+file).c_str());
+ if (Debug == true)
+ cout << "Skipping nonexistent in " << prefix << " file " << file << std::endl;
return true;
}
- if (!Record)
+ if (!Record)
{
_error->Warning(_("Can't find authentication record for: %s"), file.c_str());
return false;
return false;
}
- if(_config->FindB("Debug::aptcdrom",false))
+ if(Debug == true)
{
cout << "File: " << prefix+file << endl;
cout << "Expected Hash " << Record->Hash.toStr() << endl;
{
if (File == FileGPG)
{
- #define SIGMSG "-----BEGIN PGP SIGNED MESSAGE-----\n"
- char buffer[sizeof(SIGMSG)];
FILE* gpg = fopen(File.c_str(), "r");
if (gpg == NULL)
return _error->Errno("RunGPGV", _("Could not open file %s"), File.c_str());
- char const * const test = fgets(buffer, sizeof(buffer), gpg);
fclose(gpg);
- if (test == NULL || strcmp(buffer, SIGMSG) != 0)
+ if (!StartsWithGPGClearTextSignature(File))
return _error->Error(_("File %s doesn't start with a clearsigned message"), File.c_str());
- #undef SIGMSG
}
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
string OrigPath = string(*I,CDROM.length());
- off_t FileSize = 0;
-
+
// Open the package file
- FileFd Pkg;
- if (RealFileExists(*I) == true)
- {
- Pkg.Open(*I,FileFd::ReadOnly);
- FileSize = Pkg.Size();
- }
- else
- {
- int fd;
- if (!DecompressFile(*I, &fd, &FileSize))
- return _error->Errno("decompress","Decompress failed for %s", (*I).c_str());
- Pkg.Fd(dup(fd));
- Pkg.Seek(0);
- }
+ FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Auto);
+ off_t const FileSize = Pkg.Size();
+
pkgTagFile Parser(&Pkg);
if (_error->PendingError() == true)
return false;
(*I).c_str() + CDROM.length());
string TargetF = _config->FindDir("Dir::State::lists") + "partial/";
TargetF += URItoFileName(S);
+ FileFd Target;
if (_config->FindB("APT::CDROM::NoAct",false) == true)
+ {
TargetF = "/dev/null";
- FileFd Target(TargetF,FileFd::WriteAtomic);
+ Target.Open(TargetF,FileFd::WriteExists);
+ } else {
+ Target.Open(TargetF,FileFd::WriteAtomic);
+ }
FILE *TargetFl = fdopen(dup(Target.Fd()),"w");
if (_error->PendingError() == true)
return false;