+ Failed = true;
+ }
+ if (Failed == true)
+ return _error->Error("Failed to fetch some archives.");
+
+ if (_config->FindB("APT::Get::Download-only",false) == true)
+ return true;
+
+ // Unpack the sources
+ pid_t Process = ExecFork();
+
+ if (Process == 0)
+ {
+ for (unsigned I = 0; I != J; I++)
+ {
+ string Dir = Dsc[I].Package + '-' + pkgBaseVersion(Dsc[I].Version.c_str());
+
+ // See if the package is already unpacked
+ struct stat Stat;
+ if (stat(Dir.c_str(),&Stat) == 0 &&
+ S_ISDIR(Stat.st_mode) != 0)
+ {
+ c0out << "Skipping unpack of already unpacked source in " << Dir << endl;
+ }
+ else
+ {
+ // Call dpkg-source
+ char S[500];
+ snprintf(S,sizeof(S),"%s -x %s",
+ _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
+ Dsc[I].Dsc.c_str());
+ if (system(S) != 0)
+ {
+ cerr << "Unpack command '" << S << "' failed." << endl;
+ _exit(1);
+ }
+ }
+
+ // Try to compile it with dpkg-buildpackage
+ if (_config->FindB("APT::Get::Compile",false) == true)
+ {
+ // Call dpkg-buildpackage
+ char S[500];
+ snprintf(S,sizeof(S),"cd %s && %s %s",
+ Dir.c_str(),
+ _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
+ _config->Find("DPkg::Build-Options","-b -uc").c_str());
+
+ if (system(S) != 0)
+ {
+ cerr << "Build command '" << S << "' failed." << endl;
+ _exit(1);
+ }
+ }
+ }
+
+ _exit(0);
+ }
+
+ // Wait for the subprocess
+ int Status = 0;
+ while (waitpid(Process,&Status,0) != Process)
+ {
+ if (errno == EINTR)
+ continue;
+ return _error->Errno("waitpid","Couldn't wait for subprocess");