X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/afb1e2e3bb580077c6c917e6ea98baad8f3c39b3..899d08fea9e10d617afaa42f51f4abda76fc508f:/apt-pkg/depcache.cc diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 5da411e4d..366687382 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -20,7 +20,9 @@ #include #include #include - + +#include +#include #include /*}}}*/ @@ -76,9 +78,6 @@ bool pkgDepCache::Init(OpProgress *Prog) // Find the proper cache slot StateCache &State = PkgState[I->ID]; State.iFlags = 0; - State.DirtyState = pkgCache::State::RemoveUnknown; - //State.AutomaticRemove = I->AutomaticRemove; - State.AutomaticRemove = pkgCache::State::RemoveUnknown; // Figure out the install version State.CandidateVer = GetCandidateVer(I); @@ -98,11 +97,81 @@ bool pkgDepCache::Init(OpProgress *Prog) } Update(Prog); + + if(Prog != 0) + Prog->Done(); return true; } /*}}}*/ +bool pkgDepCache::readStateFile(OpProgress *Prog) +{ + FileFd state_file; + string state = _config->FindDir("Dir::State") + "pkgstates"; + if(FileExists(state)) { + state_file.Open(state, FileFd::ReadOnly); + int file_size = state_file.Size(); + if(Prog != NULL) + Prog->OverallProgress(0, file_size, 1, + _("Reading state information")); + + pkgTagFile tagfile(&state_file); + pkgTagSection section; + int amt=0; + while(tagfile.Step(section)) { + string pkgname = section.FindS("Package"); + pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname); + // Silently ignore unknown packages and packages with no actual + // version. + if(!pkg.end() && !pkg.VersionList().end()) { + short reason = section.FindI("Install-Reason", 0); + if(reason > 0) + PkgState[pkg->ID].Flags |= pkgCache::Flag::Auto; + if(_config->FindB("Debug::pkgAutoRemove",false)) + std::cout << "Install-Reason for: " << pkgname + << " is " << reason << std::endl; + amt+=section.size(); + if(Prog != NULL) + Prog->OverallProgress(amt, file_size, 1, + _("Reading state information")); + } + if(Prog != NULL) + Prog->OverallProgress(file_size, file_size, 1, + _("Reading state information")); + } + } + + return true; +} + +bool pkgDepCache::writeStateFile(OpProgress *prog) +{ + FileFd StateFile; + string state = _config->FindDir("Dir::State") + "pkgstates"; + + if(_config->FindB("Debug::pkgAutoRemove",false)) + std::clog << "pkgDepCache::writeStateFile()" << std::endl; + + if(!StateFile.Open(state, FileFd::WriteEmpty)) + return _error->Error(_("Failed to write StateFile %s"), + state.c_str()); + + std::ostringstream ostr; + for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end();pkg++) { + + if(PkgState[pkg->ID].Flags & pkgCache::Flag::Auto) { + if(_config->FindB("Debug::pkgAutoRemove",false)) + std::clog << "AutoInstal: " << pkg.Name() << std::endl; + ostr.str(string("")); + ostr << "Package: " << pkg.Name() + << "\nInstall-Reason: 1\n\n"; + StateFile.Write(ostr.str().c_str(), ostr.str().size()); + } + } + return true; +} + // DepCache::CheckDep - Checks a single dependency /*{{{*/ // --------------------------------------------------------------------- /* This first checks the dependency against the main target package and @@ -454,34 +523,7 @@ void pkgDepCache::Update(OpProgress *Prog) AddStates(I); } - // read the state file ------------------------------ - FileFd state_file; - string state = _config->FindDir("Dir::State") + "pkgstates"; - if(FileExists(state)) { - state_file.Open(state, FileFd::ReadOnly); - int file_size = state_file.Size(); - Prog->OverallProgress(0, file_size, 1, _("Reading extended state information")); - - pkgTagFile tagfile(&state_file); - pkgTagSection section; - int amt=0; - while(tagfile.Step(section)) { - string pkgname = section.FindS("Package"); - pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname); - // Silently ignore unknown packages and packages with no actual - // version. - if(!pkg.end() && !pkg.VersionList().end()) { - short reason = section.FindI("Remove-Reason", pkgCache::State::RemoveManual); - PkgState[pkg->ID].AutomaticRemove = reason; - //std::cout << "Set: " << pkgname << " to " << reason << std::endl; - amt+=section.size(); - Prog->OverallProgress(amt, file_size, 1, _("Reading extended state information")); - } - Prog->OverallProgress(file_size, file_size, 1, _("Reading extended state information")); - } - } - //-------------------------------------- - + readStateFile(Prog); if (Prog != 0) Prog->Progress(Done); @@ -791,15 +833,6 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To) AddSizes(Pkg); } /*}}}*/ -// DepCache::SetDirty - Switch the package between dirty states /*{{{*/ -// --------------------------------------------------------------------- -/* */ -void pkgDepCache::SetDirty(PkgIterator const &Pkg, pkgCache::State::PkgRemoveState To) -{ - StateCache &P = PkgState[Pkg->ID]; - P.DirtyState = To; -} - /*}}}*/ // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/ // --------------------------------------------------------------------- /* */