#include <sstream>
#include <stdio.h>
#include <ctime>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
#include <apti18n.h>
/*}}}*/
std::cerr << "\t- " << hs->toStr() << std::endl;
}
/*}}}*/
+static void changeOwnerAndPermissionOfFile(char const * const requester, char const * const file, char const * const user, char const * const group, mode_t const mode)
+{
+ // ensure the file is owned by root and has good permissions
+ struct passwd const * const pw = getpwnam(user);
+ struct group const * const gr = getgrnam(group);
+ if (getuid() == 0) // if we aren't root, we can't chown, so don't try it
+ {
+ if (pw != NULL && gr != NULL && chown(file, pw->pw_uid, gr->gr_gid) != 0)
+ _error->WarningE(requester, "chown to %s:%s of file %s failed", user, group, file);
+ }
+ if (chmod(file, mode) != 0)
+ _error->WarningE(requester, "chmod 0%o of file %s failed", mode, file);
+}
+static std::string preparePartialFile(std::string const &file)
+{
+ std::string DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+ DestFile += file;
+ return DestFile;
+}
+static std::string preparePartialFileFromURI(std::string const &uri)
+{
+ return preparePartialFile(URItoFileName(uri));
+}
+
// Acquire::Item::Item - Constructor /*{{{*/
#if __GNUC__ >= 4
return true;
}
/*}}}*/
+
+void pkgAcquire::Item::QueueURI(ItemDesc &Item)
+{
+ if (access(DestFile.c_str(), R_OK) == 0)
+ {
+ changeOwnerAndPermissionOfFile("preparePartialFile", DestFile.c_str(), "_apt", "root", 0600);
+ std::cerr << "QUEUE ITEM: " << DestFile << std::endl;
+ }
+ Owner->Enqueue(Item);
+}
+void pkgAcquire::Item::Dequeue()
+{
+ Owner->Dequeue(this);
+}
+
bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const error)/*{{{*/
{
if(FileExists(DestFile))
Desc.ShortDesc = Target->ShortDesc;
Desc.URI = Target->URI + ".diff/Index";
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(Desc.URI);
+ DestFile = preparePartialFileFromURI(Desc.URI);
if(Debug)
std::clog << "pkgAcqDiffIndex: " << Desc.URI << std::endl;
{
// FIXME: make this use the method
PackagesFileReadyInPartial = true;
- std::string Partial = _config->FindDir("Dir::State::lists");
- Partial += "partial/" + URItoFileName(RealURI);
+ std::string const Partial = preparePartialFileFromURI(RealURI);
FileFd From(CurrentPackagesFile, FileFd::ReadOnly);
FileFd To(Partial, FileFd::WriteEmpty);
: pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, MetaIndexParser),
available_patches(diffs), ServerSha1(ServerSha1)
{
-
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(Target->URI);
+ DestFile = preparePartialFileFromURI(Target->URI);
Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
}
// queue for copy
- PartialFile = _config->FindDir("Dir::State::lists")+"partial/"+URItoFileName(RealURI);
+ PartialFile = preparePartialFileFromURI(RealURI);
DestFile = _config->FindDir("Dir::State::lists");
DestFile += URItoFileName(RealURI);
bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
{
// calc sha1 of the just patched file
- string FinalFile = _config->FindDir("Dir::State::lists");
- FinalFile += "partial/" + URItoFileName(RealURI);
+ std::string const FinalFile = preparePartialFileFromURI(RealURI);
if(!FileExists(FinalFile))
{
// queue the right diff
Desc.URI = RealURI + ".diff/" + available_patches[0].file + ".gz";
Desc.Description = Description + " " + available_patches[0].file + string(".pdiff");
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(RealURI + ".diff/" + available_patches[0].file);
+ DestFile = preparePartialFileFromURI(RealURI + ".diff/" + available_patches[0].file);
if(Debug)
std::clog << "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc.URI << std::endl;
Item::Done(Message, Size, Hashes, Cnf);
// FIXME: verify this download too before feeding it to rred
-
- string FinalFile;
- FinalFile = _config->FindDir("Dir::State::lists")+"partial/"+URItoFileName(RealURI);
+ std::string const FinalFile = preparePartialFileFromURI(RealURI);
// success in downloading a diff, enter ApplyDiff state
if(State == StateFetchDiff)
: pkgAcqBaseIndex(Owner, TransactionManager, Target, ExpectedHashes, MetaIndexParser),
patch(patch), allPatches(allPatches), State(StateFetchDiff)
{
-
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(Target->URI);
-
Debug = _config->FindB("Debug::pkgAcquire::Diffs",false);
RealURI = Target->URI;
Desc.URI = RealURI + ".diff/" + patch.file + ".gz";
Desc.Description = Description + " " + patch.file + string(".pdiff");
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(RealURI + ".diff/" + patch.file);
+
+ DestFile = preparePartialFileFromURI(RealURI + ".diff/" + patch.file);
if(Debug)
std::clog << "pkgAcqIndexMergeDiffs: " << Desc.URI << std::endl;
Item::Done(Message,Size,Hashes,Cnf);
// FIXME: verify download before feeding it to rred
-
- string const FinalFile = _config->FindDir("Dir::State::lists") + "partial/" + URItoFileName(RealURI);
+ string const FinalFile = preparePartialFileFromURI(RealURI);
if (State == StateFetchDiff)
{
for (std::vector<pkgAcqIndexMergeDiffs *>::const_iterator I = allPatches->begin();
I != allPatches->end(); ++I)
{
- std::string PartialFile = _config->FindDir("Dir::State::lists");
- PartialFile += "partial/" + URItoFileName(RealURI);
+ std::string const PartialFile = preparePartialFileFromURI(RealURI);
std::string patch = PartialFile + ".ed." + (*I)->patch.file + ".gz";
std::cerr << patch << std::endl;
unlink(patch.c_str());
{
Stage = STAGE_DOWNLOAD;
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(URI);
+ DestFile = preparePartialFileFromURI(URI);
CurrentCompressionExtension = CompressionExtensions.substr(0, CompressionExtensions.find(' '));
if (CurrentCompressionExtension == "uncompressed")
{
// update destfile to *not* include the compression extension when doing
// a reverify (as its uncompressed on disk already)
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(RealURI);
+ DestFile = preparePartialFileFromURI(RealURI);
// adjust DestFile if its compressed on disk
if (_config->FindB("Acquire::GzipIndexes",false) == true)
// If we have compressed indexes enabled, queue for hash verification
if (_config->FindB("Acquire::GzipIndexes",false))
{
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(RealURI) + '.' + CurrentCompressionExtension;
+ DestFile = preparePartialFileFromURI(RealURI + '.' + CurrentCompressionExtension);
EraseFileName = "";
Stage = STAGE_DECOMPRESS_AND_VERIFY;
Desc.URI = "copy:" + FileName;
(*I)->Status = pkgAcquire::Item::StatDone;
// kill files in partial
- string PartialFile = _config->FindDir("Dir::State::lists");
- PartialFile += "partial/";
- PartialFile += flNotDir((*I)->DestFile);
+ std::string const PartialFile = preparePartialFile(flNotDir((*I)->DestFile));
if(FileExists(PartialFile))
Rename(PartialFile, PartialFile + ".FAILED");
}
{
if((*I)->PartialFile != "")
{
- if(_config->FindB("Debug::Acquire::Transaction", false) == true)
- std::clog << "mv "
- << (*I)->PartialFile << " -> "
- << (*I)->DestFile << " "
- << (*I)->DescURI()
- << std::endl;
- Rename((*I)->PartialFile, (*I)->DestFile);
- chmod((*I)->DestFile.c_str(),0644);
+ if(_config->FindB("Debug::Acquire::Transaction", false) == true)
+ std::clog << "mv " << (*I)->PartialFile << " -> "<< (*I)->DestFile << " "
+ << (*I)->DescURI() << std::endl;
+
+ Rename((*I)->PartialFile, (*I)->DestFile);
+ changeOwnerAndPermissionOfFile("CommitTransaction", (*I)->DestFile.c_str(), "root", "root", 0644);
+
} else {
if(_config->FindB("Debug::Acquire::Transaction", false) == true)
- std::clog << "rm "
+ std::clog << "rm "
<< (*I)->DestFile
- << " "
+ << " "
<< (*I)->DescURI()
<< std::endl;
unlink((*I)->DestFile.c_str());
// this ensures that any file in the lists/ dir is removed by the
// transaction
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(RealURI);
+ DestFile = preparePartialFileFromURI(RealURI);
TransactionManager->TransactionStageRemoval(this, DestFile);
// only allow going further if the users explicitely wants it
// pkgAcqMetaIndex::Init - Delayed constructor /*{{{*/
void pkgAcqMetaIndex::Init(std::string URIDesc, std::string ShortDesc)
{
- DestFile = _config->FindDir("Dir::State::lists") + "partial/";
- DestFile += URItoFileName(RealURI);
+ DestFile = preparePartialFileFromURI(RealURI);
// Create the item
Desc.Description = URIDesc;
return true;
}
/*}}}*/
- /*{{{*/
+// pkgAcqMetaBase::QueueForSignatureVerify /*{{{*/
void pkgAcqMetaBase::QueueForSignatureVerify(const std::string &MetaIndexFile,
const std::string &MetaIndexFileSignature)
{
SetActiveSubprocess("gpgv");
}
/*}}}*/
- /*{{{*/
+// pkgAcqMetaBase::CheckDownloadDone /*{{{*/
bool pkgAcqMetaBase::CheckDownloadDone(const std::string &Message,
const std::string &RealURI)
{
if ((unsigned long long)Buf.st_size > Version->Size)
unlink(DestFile.c_str());
else
+ {
PartialSize = Buf.st_size;
+ changeOwnerAndPermissionOfFile("pkgAcqArchive::QueueNext", FinalFile.c_str(), "_apt", "root", 0600);
+ }
}
// Disables download of archives - useful if no real installation follows,
return;
}
- Complete = true;
-
// Reference filename
if (FileName != DestFile)
{
StoreFilename = DestFile = FileName;
Local = true;
+ Complete = true;
return;
}
-
+
// Done, move it into position
string FinalFile = _config->FindDir("Dir::Cache::Archives");
FinalFile += flNotDir(StoreFilename);
Rename(DestFile,FinalFile);
-
+ changeOwnerAndPermissionOfFile("pkgAcqArchive::Done", FinalFile.c_str(), "root", "root", 0644);
StoreFilename = DestFile = FinalFile;
Complete = true;
}
if ((Size > 0) && (unsigned long long)Buf.st_size > Size)
unlink(DestFile.c_str());
else
+ {
PartialSize = Buf.st_size;
+ changeOwnerAndPermissionOfFile("pkgAcqFile", DestFile.c_str(), "_apt", "root", 0600);
+ }
}
QueueURI(Desc);