#include <apt-pkg/progress.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/indexrecords.h>
using namespace std;
-// DecompressFile - wrapper for decompressing gzip/bzip2/xz compressed files /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool DecompressFile(string Filename, int *fd, off_t *FileSize)
-{
- string CompressProg;
- string CompressProgFind;
- FileFd From;
- struct stat Buf;
- *fd = -1;
-
- if (stat((Filename + ".gz").c_str(), &Buf) == 0)
- {
- CompressProg = "gzip";
- CompressProgFind = "Dir::bin::gzip";
- From.Open(Filename + ".gz",FileFd::ReadOnly);
- }
- else if (stat((Filename + ".bz2").c_str(), &Buf) == 0)
- {
- CompressProg = "bzip2";
- CompressProgFind = "Dir::bin::bzip2";
- From.Open(Filename + ".bz2",FileFd::ReadOnly);
- }
- else if (stat((Filename + ".xz").c_str(), &Buf) == 0)
- {
- CompressProg = "xz";
- CompressProgFind = "Dir::bin::xz";
- From.Open(Filename + ".xz",FileFd::ReadOnly);
- }
- else
- {
- return _error->Errno("decompressor", "Unable to parse file");
- }
-
- if (_error->PendingError() == true)
- return -1;
-
- *FileSize = Buf.st_size;
-
- // Get a temp file
- FILE *tmp = tmpfile();
- if (tmp == 0)
- return _error->Errno("tmpfile","Unable to create a tmp file");
- *fd = dup(fileno(tmp));
- fclose(tmp);
-
- // Fork decompressor
- pid_t Process = fork();
- if (Process < 0)
- return _error->Errno("fork","Couldn't fork to run decompressor");
-
- // The child
- if (Process == 0)
- {
- dup2(From.Fd(),STDIN_FILENO);
- dup2(*fd,STDOUT_FILENO);
- SetCloseExec(STDIN_FILENO,false);
- SetCloseExec(STDOUT_FILENO,false);
-
- const char *Args[3];
- string Tmp = _config->Find(CompressProgFind, CompressProg);
- Args[0] = Tmp.c_str();
- Args[1] = "-d";
- Args[2] = 0;
- if(execvp(Args[0],(char **)Args))
- return(_error->Errno("decompressor","decompress failed"));
- /* Should never get here */
- exit(100);
- }
-
- // Wait for decompress to finish
- if (ExecWait(Process,CompressProg.c_str(),false) == false)
- return false;
-
- return true;
-}
- /*}}}*/
// IndexCopy::CopyPackages - Copy the package files from the CD /*{{{*/
// ---------------------------------------------------------------------
/* */
// Prepare the progress indicator
off_t TotalSize = 0;
+ std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
struct stat Buf;
- if (stat(string(*I + GetFileName()).c_str(),&Buf) != 0 &&
- stat(string(*I + GetFileName() + ".gz").c_str(),&Buf) != 0 &&
- stat(string(*I + GetFileName() + ".xz").c_str(),&Buf) != 0 &&
- stat(string(*I + GetFileName() + ".bz2").c_str(),&Buf) != 0)
- return _error->Errno("stat","Stat failed for %s",
- string(*I + GetFileName()).c_str());
+ bool found = false;
+ std::string file = std::string(*I).append(GetFileName());
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ {
+ if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+ continue;
+ found = true;
+ break;
+ }
+
+ if (found == false)
+ return _error->Errno("stat", "Stat failed for %s", file.c_str());
TotalSize += Buf.st_size;
- }
+ }
off_t CurrentSize = 0;
unsigned int NotFound = 0;
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)
string const releasegpg = *I+"Release.gpg";
string const release = *I+"Release";
+ string const inrelease = *I+"InRelease";
+ bool useInRelease = true;
// a Release.gpg without a Release should never happen
- if(RealFileExists(release) == false)
+ if (RealFileExists(inrelease) == true)
+ ;
+ else if(RealFileExists(release) == false || RealFileExists(releasegpg) == false)
{
delete MetaIndex;
continue;
}
+ else
+ useInRelease = false;
pid_t pid = ExecFork();
if(pid < 0) {
return false;
}
if(pid == 0)
- RunGPGV(release, releasegpg);
+ {
+ if (useInRelease == true)
+ RunGPGV(inrelease, inrelease);
+ else
+ RunGPGV(release, releasegpg);
+ }
if(!ExecWait(pid, "gpgv")) {
_error->Warning("Signature verification failed for: %s",
- releasegpg.c_str());
+ (useInRelease ? inrelease.c_str() : releasegpg.c_str()));
// something went wrong, don't copy the Release.gpg
// FIXME: delete any existing gpg file?
continue;
delete MetaIndex;
// everything was fine, copy the Release and Release.gpg file
- CopyMetaIndex(CDROM, Name, prefix, "Release");
- CopyMetaIndex(CDROM, Name, prefix, "Release.gpg");
+ if (useInRelease == true)
+ CopyMetaIndex(CDROM, Name, prefix, "InRelease");
+ else
+ {
+ CopyMetaIndex(CDROM, Name, prefix, "Release");
+ CopyMetaIndex(CDROM, Name, prefix, "Release.gpg");
+ }
}
return true;
// Prepare the progress indicator
off_t TotalSize = 0;
+ std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
struct stat Buf;
-
- if (stat(string(*I).c_str(),&Buf) != 0 &&
- stat(string(*I + ".gz").c_str(),&Buf) != 0 &&
- stat(string(*I + ".bz2").c_str(),&Buf) != 0 &&
- stat(string(*I + ".xz").c_str(),&Buf) != 0)
- return _error->Errno("stat","Stat failed for %s",
- string(*I).c_str());
+ bool found = false;
+ std::string file = *I;
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ {
+ if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+ continue;
+ found = true;
+ break;
+ }
+
+ if (found == false)
+ return _error->Errno("stat", "Stat failed for %s", file.c_str());
TotalSize += Buf.st_size;
- }
+ }
off_t CurrentSize = 0;
unsigned int NotFound = 0;
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;