diff options
author | CoolStar <coolstarorganization@gmail.com> | 2019-05-02 01:02:42 -0700 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2019-12-26 15:24:16 -1000 |
commit | d784ec66fa0019ae1b359578a85488649fdbd621 (patch) | |
tree | c6f902c34d81b7326084fff2aac4ec31889a8362 | |
parent | 713b65be84830af1a57148b44dc1d1d4010ece3e (diff) |
1.8.0-Sileosille-apt
-rw-r--r-- | apt-pkg/CMakeLists.txt | 3 | ||||
-rw-r--r-- | apt-pkg/algorithms.h | 3 | ||||
-rw-r--r-- | apt-pkg/algorithms.mm (renamed from apt-pkg/algorithms.cc) | 138 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.h | 2 | ||||
-rw-r--r-- | apt-pkg/deb/debmetaindex.cc | 4 | ||||
-rw-r--r-- | apt-pkg/edsp.cc | 9 | ||||
-rw-r--r-- | apt-private/CMakeLists.txt | 4 | ||||
-rw-r--r-- | apt-private/private-output.mm (renamed from apt-private/private-output.cc) | 284 | ||||
-rw-r--r-- | cmdline/CMakeLists.txt | 7 | ||||
-rw-r--r-- | cmdline/sileo-solver.cc | 214 | ||||
-rw-r--r-- | methods/CMakeLists.txt | 20 | ||||
-rw-r--r-- | methods/nshttp.h | 40 | ||||
-rw-r--r-- | methods/nshttp.mm | 196 |
13 files changed, 482 insertions, 442 deletions
diff --git a/apt-pkg/CMakeLists.txt b/apt-pkg/CMakeLists.txt index 64709ce34..09c82d7e6 100644 --- a/apt-pkg/CMakeLists.txt +++ b/apt-pkg/CMakeLists.txt @@ -32,7 +32,7 @@ set(APT_PKG_MAJOR ${MAJOR} PARENT_SCOPE) # exporting for methods/CMakeLists.txt # Definition of the C++ files used to build the library - note that this # is expanded at CMake time, so you have to rerun cmake if you add or remove # a file (you can just run cmake . in the build directory) -file(GLOB_RECURSE library "*.cc" "${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc") +file(GLOB_RECURSE library "*.cc" "*.mm" "${CMAKE_CURRENT_BINARY_DIR}/tagfile-keys.cc") file(GLOB_RECURSE headers "*.h") # Create a library using the C++ files @@ -59,6 +59,7 @@ target_link_libraries(apt-pkg $<$<BOOL:${ZSTD_FOUND}>:${ZSTD_LIBRARIES}> $<$<BOOL:${UDEV_FOUND}>:${UDEV_LIBRARIES}> ${ICONV_LIBRARIES} + "-framework Foundation" ) set_target_properties(apt-pkg PROPERTIES VERSION ${MAJOR}.${MINOR}) set_target_properties(apt-pkg PROPERTIES SOVERSION ${MAJOR}) diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index c5c9f4c69..7637f6d1d 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -87,6 +87,9 @@ public: private: APT_HIDDEN void ShortBreaks(); APT_HIDDEN void Describe(PkgIterator iPkg,std::ostream &out,bool Current,bool Candidate); +#if ENABLE_SILEO + APT_HIDDEN NSMutableDictionary * DescribeSileo(PkgIterator iPkg,bool Current,bool Candidate); +#endif APT_HIDDEN bool RealInstall(PkgIterator Pkg,std::string File); APT_HIDDEN bool RealConfigure(PkgIterator Pkg); APT_HIDDEN bool RealRemove(PkgIterator Pkg,bool Purge); diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.mm index 4c34e5989..be0acb178 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.mm @@ -15,6 +15,9 @@ // Include Files /*{{{*/ #include <config.h> +#define ENABLE_SILEO 1 +#include <Foundation/Foundation.h> + #include <apt-pkg/algorithms.h> #include <apt-pkg/configuration.h> #include <apt-pkg/depcache.h> @@ -73,32 +76,6 @@ pkgSimulate::~pkgSimulate() Parameter Candidate == true displays the candidate package version */ void pkgSimulate::Describe(PkgIterator Pkg,ostream &out,bool Current,bool Candidate) { - bool forSileo = _config->FindB("APT::Format::for-sileo", false); - if (forSileo){ - VerIterator Ver(Sim); - - out << "\"Package\":\"" << Pkg.FullName(true) << "\""; - - if (Current == true) - { - Ver = Pkg.CurrentVer(); - if (Ver.end() == false) - out << ",\"Version\":\"" << Ver.VerStr() << '"'; - } - - if (Candidate == true) - { - Ver = Sim[Pkg].CandidateVerIter(Sim); - if (Ver.end() == true) - return; - - out << ",\"Version\":\"" << Ver.VerStr() << '"'; - out << ",\"Release\":\"" << Ver.RelStr() << '"'; - } - out << "}"; - return; - } - VerIterator Ver(Sim); out << Pkg.FullName(true); @@ -120,6 +97,37 @@ void pkgSimulate::Describe(PkgIterator Pkg,ostream &out,bool Current,bool Candid } } /*}}}*/ +// Simulate::DescribeSileo - Describe a package /*{{{*/ +// --------------------------------------------------------------------- +/* Parameter Current == true displays the current package version, + Parameter Candidate == true displays the candidate package version */ +NSMutableDictionary * pkgSimulate::DescribeSileo(PkgIterator Pkg,bool Current,bool Candidate) +{ + VerIterator Ver(Sim); + + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + [dictionary setObject:[NSString stringWithUTF8String:Pkg.FullName(true).c_str()] forKey:@"Package"]; + + if (Current == true) + { + Ver = Pkg.CurrentVer(); + if (Ver.end() == false){ + [dictionary setObject:[NSString stringWithUTF8String:Ver.VerStr()] forKey:@"Version"]; + } + } + + if (Candidate == true) + { + Ver = Sim[Pkg].CandidateVerIter(Sim); + if (Ver.end() == true) + return dictionary; + [dictionary setObject:[NSString stringWithUTF8String:Ver.VerStr()] forKey:@"Version"]; + [dictionary setObject:[NSString stringWithUTF8String:Ver.RelStr().c_str()] forKey:@"Release"]; + } + + return dictionary; +} + /*}}}*/ // Simulate::Install - Simulate unpacking of a package /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -137,39 +145,41 @@ bool pkgSimulate::RealInstall(PkgIterator iPkg,string /*File*/) // Adapt the iterator PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); Flags[Pkg->ID] = 1; - - cout << "{\"Type\":\"Inst\","; - Describe(Pkg,cout,true,true); + + NSMutableDictionary *package = DescribeSileo(Pkg, true, true); + [package setObject:@"Inst" forKey:@"Type"]; + + cout << flush; + + NSData *data = [NSJSONSerialization dataWithJSONObject:package options:0 error:nil]; + NSFileHandle *stdout = [NSFileHandle fileHandleWithStandardOutput]; + [stdout writeData:data]; + + cout << endl; + Sim.MarkInstall(Pkg,false); // Look for broken conflicts+predepends. for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I) { if (Sim[I].InstallVer == 0) - continue; - + continue; + for (DepIterator D = Sim[I].InstVerIter(Sim).DependsList(); D.end() == false;) { - DepIterator Start; - DepIterator End; - D.GlobOr(Start,End); - if (Start.IsNegative() == true || - End->Type == pkgCache::Dep::PreDepends) + DepIterator Start; + DepIterator End; + D.GlobOr(Start,End); + if (Start.IsNegative() == true || End->Type == pkgCache::Dep::PreDepends) { - if ((Sim[End] & pkgDepCache::DepGInstall) == 0) - { - cout << " [" << I.FullName(false) << " on " << Start.TargetPkg().FullName(false) << ']'; - if (Start->Type == pkgCache::Dep::Conflicts) - _error->Error("Fatal, conflicts violated %s",I.FullName(false).c_str()); - } - } + if ((Sim[End] & pkgDepCache::DepGInstall) == 0) + { + if (Start->Type == pkgCache::Dep::Conflicts) + _error->Error("Fatal, conflicts violated %s",I.FullName(false).c_str()); + } + } } } - - if (Sim.BrokenCount() != 0) - ShortBreaks(); - else - cout << endl; return true; } @@ -227,6 +237,7 @@ bool pkgSimulate::Configure(PkgIterator iPkg) bool pkgSimulate::RealConfigure(PkgIterator iPkg) { bool forSileo = _config->FindB("APT::Format::for-sileo", false); + // Adapt the iterator PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); @@ -264,12 +275,12 @@ bool pkgSimulate::RealConfigure(PkgIterator iPkg) cout << "Conf "; Describe(Pkg,cout,false,true); } - } - if (Sim.BrokenCount() != 0) - ShortBreaks(); - else if (!forSileo) - cout << endl; + if (Sim.BrokenCount() != 0) + ShortBreaks(); + else + cout << endl; + } return true; } @@ -287,7 +298,7 @@ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge) bool pkgSimulate::RealRemove(PkgIterator iPkg,bool Purge) { bool forSileo = _config->FindB("APT::Format::for-sileo", false); - + // Adapt the iterator PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); if (Pkg.end() == true) @@ -300,25 +311,30 @@ bool pkgSimulate::RealRemove(PkgIterator iPkg,bool Purge) Sim.MarkDelete(Pkg); if (forSileo){ + NSMutableDictionary *package = DescribeSileo(Pkg, true, false); if (Purge == true) - cout << "{\"Type\":\"Purg\","; + [package setObject:@"Purg" forKey:@"Type"]; else - cout << "{\"Type\":\"Remv\","; + [package setObject:@"Remv" forKey:@"Type"]; + + cout << flush; + + NSData *data = [NSJSONSerialization dataWithJSONObject:package options:0 error:nil]; + NSFileHandle *stdout = [NSFileHandle fileHandleWithStandardOutput]; + [stdout writeData:data]; + + cout << endl; } else { if (Purge == true) cout << "Purg "; else cout << "Remv "; - } - Describe(Pkg,cout,true,false); + Describe(Pkg,cout,true,false); - if (!forSileo){ if (Sim.BrokenCount() != 0) ShortBreaks(); else cout << endl; - } else { - cout << endl; } return true; diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 4cde9f56f..f02252d58 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -52,8 +52,6 @@ class APT_HIDDEN debListParser : public pkgCacheListParser pkgTagSection Section; map_filesize_t iOffset; - std::string Arch; - virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver); bool ParseDepends(pkgCache::VerIterator &Ver, pkgTagSection::Key Key, unsigned int Type); diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 98bac7a70..f88076abf 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -565,10 +565,6 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro if (CheckValidUntil == true) { - - if (Date == 0) - strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Date", Filename.c_str()); - std::string const StrValidUntil = Section.FindS("Valid-Until"); // if we have a Valid-Until header in the Release file, use it as default diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 9879fd8b3..2e39be377 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -661,15 +661,6 @@ bool EDSP::ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progres _error->Error("External solver failed with: %s", msg.substr(0,msg.find('\n')).c_str()); if (Progress != nullptr) Progress->Done(); - - bool forSileo = _config->FindB("APT::Format::for-sileo", false); - if (forSileo){ - std::cerr << "SOLVERR: " << section.FindS("Error") << std::endl; - std::cerr << "SOLVINFO:" << std::endl; - std::cerr << msg << std::endl << std::endl; - return false; - } - std::cerr << "The solver encountered an error of type: " << section.FindS("Error") << std::endl; std::cerr << "The following information might help you to understand what is wrong:" << std::endl; std::cerr << msg << std::endl << std::endl; diff --git a/apt-private/CMakeLists.txt b/apt-private/CMakeLists.txt index 88a8f97fe..4a6ea51b8 100644 --- a/apt-private/CMakeLists.txt +++ b/apt-private/CMakeLists.txt @@ -5,14 +5,14 @@ set(MINOR 0) # Definition of the C++ files used to build the library - note that this # is expanded at CMake time, so you have to rerun cmake if you add or remove # a file (you can just run cmake . in the build directory) -file(GLOB_RECURSE library "*.cc") +file(GLOB_RECURSE library "*.cc" "*.mm") file(GLOB_RECURSE headers "*.h") # Create a library using the C++ files add_library(apt-private SHARED ${library}) # Link the library and set the SONAME -target_link_libraries(apt-private PUBLIC apt-pkg) +target_link_libraries(apt-private PUBLIC apt-pkg "-framework Foundation") set_target_properties(apt-private PROPERTIES VERSION ${MAJOR}.${MINOR}) set_target_properties(apt-private PROPERTIES SOVERSION ${MAJOR}) set_target_properties(apt-private PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/apt-private/private-output.cc b/apt-private/private-output.mm index 3c7e38c0e..2e9d0fd0f 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.mm @@ -1,6 +1,8 @@ // Include files /*{{{*/ #include <config.h> +#include <Foundation/Foundation.h> + #include <apt-pkg/cachefile.h> #include <apt-pkg/configuration.h> #include <apt-pkg/depcache.h> @@ -328,126 +330,17 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed Depends: libsasl7 but it is not going to be installed */ -static bool ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now, bool const DisplaySeparator) +static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now) { if (Now == true) { if ((*Cache)[Pkg].NowBroken() == false) - return false; + return; } else { if ((*Cache)[Pkg].InstBroken() == false) - return false; - } - - bool useJSON = _config->FindB("APT::Format::for-sileo", false); - if (useJSON){ - if (DisplaySeparator) - out << ","; - - // Print out each package and the failed dependencies - out << "\"" << Pkg.FullName(true) << "\":["; - bool First = true; - pkgCache::VerIterator Ver; - - if (Now == true) - Ver = Pkg.CurrentVer(); - else - Ver = (*Cache)[Pkg].InstVerIter(*Cache); - - if (Ver.end() == true) - { - out << "]" << endl; - return true; - } - - for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) - { - // Compute a single dependency element (glob or) - pkgCache::DepIterator Start; - pkgCache::DepIterator End; - D.GlobOr(Start,End); // advances D - - if ((*Cache)->IsImportantDep(End) == false) - continue; - - if (Now == true) - { - if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow) - continue; - } - else - { - if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) - continue; - } - - bool FirstOr = true; - while (1) - { - if (!First) - out << ","; - - First = false; - - if (FirstOr == false) - { - out << ","; - } - else - out << "["; - out << "{\"Type\":\"" << End.DepType() << "\""; - FirstOr = false; - - out << ",\"Package\":\"" << Start.TargetPkg().FullName(true) << "\""; - - // Show a quick summary of the version requirements - if (Start.TargetVer() != 0) - out << ",\"VersionSummary\":\"" << Start.CompType() << " " << Start.TargetVer() << "\""; - - /* Show a summary of the target package if possible. In the case - of virtual packages we show nothing */ - pkgCache::PkgIterator Targ = Start.TargetPkg(); - if (Targ->ProvidesList == 0) - { - pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache); - if (Now == true) - Ver = Targ.CurrentVer(); - - if (Ver.end() == false) - { - if (Now == true) - ioprintf(out,_(",\"Reason\":\"%s is installed\""),Ver.VerStr()); - else - ioprintf(out,_(",\"Reason\":\"%s is to be installed\""),Ver.VerStr()); - } - else - { - if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true) - { - if (Targ->ProvidesList == 0) - out << _(",\"Reason\":\"it is not installable\""); - else - out << _(",\"Reason\":\"it is a virtual package\""); - } - else - out << (Now?_(",\"Reason\":\"it is not installed\""):_(",\"Reason\":\"it is not going to be installed\"")); - } - } - - out << "}"; - - if (Start == End){ - out << "]"; - break; - } - ++Start; - } - } - out << "]"; - - return true; + return; } // Print out each package and the failed dependencies @@ -464,7 +357,7 @@ static bool ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache if (Ver.end() == true) { out << endl; - return true; + return; } for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) @@ -551,8 +444,119 @@ static bool ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache ++Start; } } - return true; } + +static NSMutableDictionary * SileoBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now) +{ + if (Now == true) + { + if ((*Cache)[Pkg].NowBroken() == false) + return nil; + } + else + { + if ((*Cache)[Pkg].InstBroken() == false) + return nil; + } + + NSMutableDictionary *packages = [NSMutableDictionary dictionary]; + + NSMutableArray *deps = [NSMutableArray array]; + + // Print out each package and the failed dependencies + [packages setObject:deps forKey:[NSString stringWithUTF8String:Pkg.FullName(true).c_str()]]; + + pkgCache::VerIterator Ver; + + if (Now == true) + Ver = Pkg.CurrentVer(); + else + Ver = (*Cache)[Pkg].InstVerIter(*Cache); + + if (Ver.end() == true) + { + return packages; + } + + for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) + { + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start; + pkgCache::DepIterator End; + D.GlobOr(Start,End); // advances D + + if ((*Cache)->IsImportantDep(End) == false) + continue; + + if (Now == true) + { + if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow) + continue; + } + else + { + if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) + continue; + } + + NSMutableArray *orDependencies = [NSMutableArray array]; + [deps addObject:orDependencies]; + + while (1) + { + + NSMutableDictionary *dependency = [NSMutableDictionary dictionary]; + [orDependencies addObject:dependency]; + [dependency setObject:[NSString stringWithUTF8String:End.DepType()] forKey:@"Type"]; + + [dependency setObject:[NSString stringWithUTF8String:Start.TargetPkg().FullName(true).c_str()] forKey:@"Package"]; + + // Show a quick summary of the version requirements + if (Start.TargetVer() != 0) + [dependency setObject:[NSString stringWithFormat:@"%s %s", Start.CompType(), Start.TargetVer()] forKey:@"VersionSummary"]; + + /* Show a summary of the target package if possible. In the case + of virtual packages we show nothing */ + pkgCache::PkgIterator Targ = Start.TargetPkg(); + if (Targ->ProvidesList == 0) + { + pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache); + if (Now == true) + Ver = Targ.CurrentVer(); + + if (Ver.end() == false) + { + if (Now == true) + [dependency setObject:[NSString stringWithFormat:@"%s is installed",Ver.VerStr()] forKey:@"Reason"]; + else + [dependency setObject:[NSString stringWithFormat:@"%s is to be installed",Ver.VerStr()] forKey:@"Reason"]; + } + else + { + if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true) + { + if (Targ->ProvidesList == 0) + [dependency setObject:@"it is not installable" forKey:@"Reason"]; + else + [dependency setObject:@"it is a virtual package" forKey:@"Reason"]; + } + else { + if (Now) + [dependency setObject:@"it is not installed" forKey:@"Reason"]; + else + [dependency setObject:@"it is not going to be installed" forKey:@"Reason"]; + } + } + } + + if (Start == End) + break; + ++Start; + } + } + return packages; +} + void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) { if (Cache->BrokenCount() == 0) @@ -561,19 +565,25 @@ void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) out << _("The following packages have unmet dependencies:") << endl; bool useJSON = _config->FindB("APT::Format::for-sileo", false); - if (useJSON) - out << "{"; - - bool DisplaySeparator = false; SortedPackageUniverse Universe(Cache); - for (auto const &Pkg: Universe){ - if (ShowBrokenPackage(out, &Cache, Pkg, Now, DisplaySeparator)) - DisplaySeparator = true; - } - if (useJSON) - out << "}"; + if (useJSON){ + NSMutableDictionary *packages = [NSMutableDictionary dictionary]; + for (auto const &Pkg: Universe){ + NSMutableDictionary *package = SileoBrokenPackage(out, &Cache, Pkg, Now); + [packages addEntriesFromDictionary:package]; + } + + cout << flush; + + NSData *data = [NSJSONSerialization dataWithJSONObject:packages options:0 error:nil]; + NSFileHandle *stdout = [NSFileHandle fileHandleWithStandardOutput]; + [stdout writeData:data]; + } else { + for (auto const &Pkg: Universe) + ShowBrokenPackage(out, &Cache, Pkg, Now); + } } void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) { @@ -583,19 +593,25 @@ void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) out << _("The following packages have unmet dependencies:") << endl; bool useJSON = _config->FindB("APT::Format::for-sileo", false); - if (useJSON) - out << "{"; - - bool DisplaySeparator = false; APT::PackageUniverse Universe(Cache); - for (auto const &Pkg: Universe){ - if (ShowBrokenPackage(out, &Cache, Pkg, Now, DisplaySeparator)) - DisplaySeparator = true; - } - if (useJSON) - out << "}"; + if (useJSON){ + NSMutableDictionary *packages = [NSMutableDictionary dictionary]; + for (auto const &Pkg: Universe){ + NSMutableDictionary *package = SileoBrokenPackage(out, &Cache, Pkg, Now); + [packages addEntriesFromDictionary:package]; + } + + cout << flush; + + NSData *data = [NSJSONSerialization dataWithJSONObject:packages options:0 error:nil]; + NSFileHandle *stdout = [NSFileHandle fileHandleWithStandardOutput]; + [stdout writeData:data]; + } else { + for (auto const &Pkg: Universe) + ShowBrokenPackage(out, &Cache, Pkg, Now); + } } /*}}}*/ // ShowNew - Show packages to newly install /*{{{*/ diff --git a/cmdline/CMakeLists.txt b/cmdline/CMakeLists.txt index dd66b843c..8977b45d1 100644 --- a/cmdline/CMakeLists.txt +++ b/cmdline/CMakeLists.txt @@ -9,7 +9,6 @@ add_executable(apt-helper apt-helper.cc) add_executable(apt-sortpkgs apt-sortpkgs.cc) add_executable(apt-extracttemplates apt-extracttemplates.cc) add_executable(apt-internal-solver apt-internal-solver.cc) -add_executable(sileo-solver sileo-solver.cc) add_executable(apt-dump-solver apt-dump-solver.cc) add_executable(apt-internal-planner apt-internal-planner.cc) add_vendor_file(OUTPUT apt-key @@ -32,7 +31,6 @@ target_link_libraries(apt-mark apt-pkg apt-private) target_link_libraries(apt-sortpkgs apt-pkg apt-private) target_link_libraries(apt-extracttemplates apt-pkg apt-inst apt-private) target_link_libraries(apt-internal-solver apt-pkg apt-inst apt-private) -target_link_libraries(sileo-solver apt-pkg apt-inst apt-private) target_link_libraries(apt-dump-solver apt-pkg apt-inst apt-private) target_link_libraries(apt-internal-planner apt-pkg apt-inst apt-private) @@ -42,9 +40,6 @@ set_target_properties(apt-dump-solver set_target_properties(apt-internal-solver PROPERTIES RUNTIME_OUTPUT_DIRECTORY solvers RUNTIME_OUTPUT_NAME apt) -set_target_properties(sileo-solver - PROPERTIES RUNTIME_OUTPUT_DIRECTORY solvers - RUNTIME_OUTPUT_NAME sileo) set_target_properties(apt-internal-planner PROPERTIES RUNTIME_OUTPUT_DIRECTORY planners RUNTIME_OUTPUT_NAME apt) @@ -55,7 +50,7 @@ install(TARGETS apt apt-cache apt-get apt-config apt-cdrom apt-mark apt-sortpkgs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS apt-helper RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/apt/) -install(TARGETS apt-dump-solver apt-internal-solver sileo-solver RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/apt/solvers) +install(TARGETS apt-dump-solver apt-internal-solver RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/apt/solvers) install(TARGETS apt-internal-planner RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/apt/planners) add_slaves(${CMAKE_INSTALL_LIBEXECDIR}/apt/planners ../solvers/dump planners/dump) diff --git a/cmdline/sileo-solver.cc b/cmdline/sileo-solver.cc deleted file mode 100644 index 0bc516c41..000000000 --- a/cmdline/sileo-solver.cc +++ /dev/null @@ -1,214 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ##################################################################### - - cover around the internal solver to be able to run it like an external - - ##################################################################### */ - /*}}}*/ -// Include Files /*{{{*/ -#include <config.h> - -#include <apt-pkg/algorithms.h> -#include <apt-pkg/cachefile.h> -#include <apt-pkg/cacheset.h> -#include <apt-pkg/cmndline.h> -#include <apt-pkg/configuration.h> -#include <apt-pkg/depcache.h> -#include <apt-pkg/edsp.h> -#include <apt-pkg/error.h> -#include <apt-pkg/fileutl.h> -#include <apt-pkg/init.h> -#include <apt-pkg/pkgcache.h> -#include <apt-pkg/pkgsystem.h> -#include <apt-pkg/strutl.h> -#include <apt-pkg/upgrade.h> - -#include <apt-private/private-cmndline.h> -#include <apt-private/private-main.h> -#include <apt-private/private-output.h> - -#include <cstdio> -#include <iostream> -#include <list> -#include <sstream> -#include <string> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <apti18n.h> - /*}}}*/ - -static bool ShowHelp(CommandLine &) /*{{{*/ -{ - std::cout << - _("Usage: sileo-solver\n" - "\n" - "sileo-solver is an interface to use the internal\n" - "resolver for the APT family for Sileo.\n"); - return true; -} - /*}}}*/ -APT_NORETURN static void DIE(std::string const &message) { /*{{{*/ - std::cerr << "ERROR: " << message << std::endl; - _error->DumpErrors(std::cerr); - exit(EXIT_FAILURE); -} - /*}}}*/ -static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ -{ - return {}; -} - /*}}}*/ -static bool WriteSolution(pkgDepCache &Cache, FileFd &output) /*{{{*/ -{ - bool Okay = output.Failed() == false; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false && likely(Okay); ++Pkg) - { - std::string action; - if (Cache[Pkg].Delete() == true) - Okay &= EDSP::WriteSolutionStanza(output, "Remove", Pkg.CurrentVer()); - else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true) - Okay &= EDSP::WriteSolutionStanza(output, "Install", Cache.GetCandidateVersion(Pkg)); - else if (Cache[Pkg].Garbage == true) - Okay &= EDSP::WriteSolutionStanza(output, "Autoremove", Pkg.CurrentVer()); - } - return Okay; -} - /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ -{ - // we really don't need anything - DropPrivileges(); - - CommandLine CmdL; - ParseCommandLine(CmdL, APT_CMD::APT_INTERNAL_SOLVER, &_config, NULL, argc, argv, &ShowHelp, &GetCommands); - - _config->Set("APT::Format::for-sileo",true); - - if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0) - { - if (pkgInitSystem(*_config,_system) == false) { - std::cerr << "System could not be initialized!" << std::endl; - return 1; - } - pkgCacheFile CacheFile; - CacheFile.Open(NULL, false); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - FileFd output; - if (output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::BufferedWrite, true) == false) - return 2; - if (pkgset.empty() == true) - EDSP::WriteScenario(CacheFile, output); - else - { - std::vector<bool> pkgvec(CacheFile->Head().PackageCount, false); - for (auto const &p: pkgset) - pkgvec[p->ID] = true; - EDSP::WriteLimitedScenario(CacheFile, output, pkgvec); - } - output.Close(); - _error->DumpErrors(std::cerr); - return 0; - } - - // Deal with stdout not being a tty - if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) - _config->Set("quiet","1"); - - if (_config->FindI("quiet", 0) < 1) - _config->Set("Debug::EDSP::WriteSolution", true); - - _config->Set("APT::System", "Debian APT solver interface"); - _config->Set("APT::Solver", "internal"); - _config->Set("edsp::scenario", "/nonexistent/stdin"); - _config->Clear("Dir::Log"); - FileFd output; - if (output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::BufferedWrite, true) == false) - DIE("stdout couldn't be opened"); - int const input = STDIN_FILENO; - SetNonBlock(input, false); - - EDSP::WriteProgress(0, "Start up solver…", output); - - if (pkgInitSystem(*_config,_system) == false) - DIE("System could not be initialized!"); - - EDSP::WriteProgress(1, "Read request…", output); - - if (WaitFd(input, false, 5) == false) - DIE("WAIT timed out in the resolver"); - - std::list<std::string> install, remove; - unsigned int flags; - if (EDSP::ReadRequest(input, install, remove, flags) == false) - DIE("Parsing the request failed!"); - - EDSP::WriteProgress(5, "Read scenario…", output); - - pkgCacheFile CacheFile; - if (CacheFile.Open(NULL, false) == false) - DIE("Failed to open CacheFile!"); - - EDSP::WriteProgress(50, "Apply request on scenario…", output); - - if (EDSP::ApplyRequest(install, remove, CacheFile) == false) - DIE("Failed to apply request to depcache!"); - - pkgProblemResolver Fix(CacheFile); - for (std::list<std::string>::const_iterator i = remove.begin(); - i != remove.end(); ++i) { - pkgCache::PkgIterator P = CacheFile->FindPkg(*i); - Fix.Clear(P); - Fix.Protect(P); - Fix.Remove(P); - } - - for (std::list<std::string>::const_iterator i = install.begin(); - i != install.end(); ++i) { - pkgCache::PkgIterator P = CacheFile->FindPkg(*i); - Fix.Clear(P); - Fix.Protect(P); - } - - for (std::list<std::string>::const_iterator i = install.begin(); - i != install.end(); ++i) - CacheFile->MarkInstall(CacheFile->FindPkg(*i), true); - - EDSP::WriteProgress(60, "Call problemresolver on current scenario…", output); - - std::string failure; - if (flags & EDSP::Request::UPGRADE_ALL) { - int upgrade_flags = APT::Upgrade::ALLOW_EVERYTHING; - if (flags & EDSP::Request::FORBID_NEW_INSTALL) - upgrade_flags |= APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES; - if (flags & EDSP::Request::FORBID_REMOVE) - upgrade_flags |= APT::Upgrade::FORBID_REMOVE_PACKAGES; - - if (APT::Upgrade::Upgrade(CacheFile, upgrade_flags)) - ; - else if (upgrade_flags == APT::Upgrade::ALLOW_EVERYTHING) - failure = "ERR_UNSOLVABLE_FULL_UPGRADE"; - else - failure = "ERR_UNSOLVABLE_UPGRADE"; - } else if (Fix.Resolve() == false) - failure = "ERR_UNSOLVABLE"; - - if (failure.empty() == false) { - std::ostringstream broken; - ShowBroken(broken, CacheFile, false); - EDSP::WriteError(failure.c_str(), broken.str(), output); - return 0; - } - - EDSP::WriteProgress(95, "Write solution…", output); - - if (WriteSolution(CacheFile, output) == false) - DIE("Failed to output the solution!"); - - EDSP::WriteProgress(100, "Done", output); - - return DispatchCommandLine(CmdL, {}); -} - /*}}}*/ diff --git a/methods/CMakeLists.txt b/methods/CMakeLists.txt index c4a32b4f5..14689bbfe 100644 --- a/methods/CMakeLists.txt +++ b/methods/CMakeLists.txt @@ -2,32 +2,34 @@ include_directories($<$<BOOL:${SECCOMP_FOUND}>:${SECCOMP_INCLUDE_DIR}>) link_libraries(apt-pkg $<$<BOOL:${SECCOMP_FOUND}>:${SECCOMP_LIBRARIES}>) -add_library(connectlib OBJECT connect.cc rfc2553emu.cc) +#add_library(connectlib OBJECT connect.cc rfc2553emu.cc) add_executable(file file.cc) add_executable(copy copy.cc) add_executable(store store.cc) add_executable(gpgv gpgv.cc) add_executable(cdrom cdrom.cc) -add_executable(http http.cc basehttp.cc $<TARGET_OBJECTS:connectlib>) +#add_executable(http http.cc basehttp.cc $<TARGET_OBJECTS:connectlib>) +add_executable(https nshttp.mm) add_executable(mirror mirror.cc) -add_executable(ftp ftp.cc $<TARGET_OBJECTS:connectlib>) +#add_executable(ftp ftp.cc $<TARGET_OBJECTS:connectlib>) add_executable(rred rred.cc) add_executable(rsh rsh.cc) -target_compile_definitions(connectlib PRIVATE ${GNUTLS_DEFINITIONS}) -target_include_directories(connectlib PRIVATE ${GNUTLS_INCLUDE_DIR}) +#target_compile_definitions(connectlib PRIVATE ${GNUTLS_DEFINITIONS}) +#target_include_directories(connectlib PRIVATE ${GNUTLS_INCLUDE_DIR}) # Additional libraries to link against for networked stuff -target_link_libraries(http ${GNUTLS_LIBRARIES}) -target_link_libraries(ftp ${GNUTLS_LIBRARIES}) +#target_link_libraries(http ${GNUTLS_LIBRARIES}) +target_link_libraries(https "-framework Foundation") +#target_link_libraries(ftp ${GNUTLS_LIBRARIES}) # Install the library -install(TARGETS file copy store gpgv cdrom http ftp rred rsh mirror +install(TARGETS file copy store https gpgv cdrom rred rsh mirror RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/apt/methods) add_slaves(${CMAKE_INSTALL_LIBEXECDIR}/apt/methods mirror mirror+ftp mirror+http mirror+https mirror+file mirror+copy) add_slaves(${CMAKE_INSTALL_LIBEXECDIR}/apt/methods rsh ssh) -add_slaves(${CMAKE_INSTALL_LIBEXECDIR}/apt/methods http https) +#add_slaves(${CMAKE_INSTALL_LIBEXECDIR}/apt/methods http https) diff --git a/methods/nshttp.h b/methods/nshttp.h new file mode 100644 index 000000000..d0a7c8c31 --- /dev/null +++ b/methods/nshttp.h @@ -0,0 +1,40 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + HTTP method - Transfer files via rsh compatible program + + ##################################################################### */ + /*}}}*/ +#ifndef APT_NSHTTP_H +#define APT_NSHTTP_H + +#include <string> +#include <time.h> + +#include <apt-pkg/strutl.h> +#include <Foundation/Foundation.h> + +class Hashes; +class FileFd; + +#include "aptmethod.h" + +class HttpMethod : public aptMethod +{ + virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE; + virtual bool Configuration(std::string Message) APT_OVERRIDE; + + NSURLSession *session; + + static std::string FailFile; + static int FailFd; + static time_t FailTime; + static APT_NORETURN void SigTerm(int); + + public: + + explicit HttpMethod(std::string &&Prog); +}; + +#endif diff --git a/methods/nshttp.mm b/methods/nshttp.mm new file mode 100644 index 000000000..4f4e438b0 --- /dev/null +++ b/methods/nshttp.mm @@ -0,0 +1,196 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + RSH method - Transfer files via rsh compatible program + + Written by Ben Collins <bcollins@debian.org>, Copyright (c) 2000 + Licensed under the GNU General Public License v2 [no exception clauses] + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include <config.h> + +#include <apt-pkg/configuration.h> +#include <apt-pkg/error.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/hashes.h> +#include <apt-pkg/strutl.h> + +#include "nshttp.h" +#include <errno.h> +#include <signal.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <unistd.h> + +#include <apti18n.h> + +unsigned long TimeOut = 30; +Configuration::Item const *HttpOptions = 0; +time_t HttpMethod::FailTime = 0; + +// HttpMethod::HttpMethod - Constructor /*{{{*/ +HttpMethod::HttpMethod(std::string &&pProg) : aptMethod(std::move(pProg),"1.0",SendConfig) +{ + signal(SIGTERM,SigTerm); + signal(SIGINT,SigTerm); +} + /*}}}*/ +// HttpMethod::Configuration - Handle a configuration message /*{{{*/ +// --------------------------------------------------------------------- +bool HttpMethod::Configuration(std::string Message) +{ + // enabling privilege dropping for this method requires configuration… + // … which is otherwise lifted straight from root, so use it by default. + _config->Set(std::string("Binary::") + Binary + "::APT::Sandbox::User", ""); + + if (aptMethod::Configuration(Message) == false) + return false; + + std::string const timeconf = std::string("Acquire::") + Binary + "::Timeout"; + TimeOut = _config->FindI(timeconf, TimeOut); + std::string const optsconf = std::string("Acquire::") + Binary + "::Options"; + HttpOptions = _config->Tree(optsconf.c_str()); + + return true; +} + /*}}}*/ +// HttpMethod::SigTerm - Clean up and timestamp the files on exit /*{{{*/ +// --------------------------------------------------------------------- +/* */ +void HttpMethod::SigTerm(int) +{ + _exit(100); +} + /*}}}*/ +// HttpMethod::Fetch - Fetch a URI /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool HttpMethod::Fetch(FetchItem *Itm) +{ + URI Get = Itm->Uri; + std::string cppGet = Get; + NSURL *URL = [NSURL URLWithString:[NSString stringWithUTF8String:cppGet.c_str()]]; + __block FetchResult Res; + Res.Filename = Itm->DestFile; + Res.IMSHit = false; + + __block BOOL success = NO; + + dispatch_semaphore_t sem = dispatch_semaphore_create(0); + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:TimeOut]; + [request setHTTPMethod:@"HEAD"]; + [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *, NSURLResponse *response, NSError *error){ + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; + if (httpResponse.statusCode >= 200){ + if (httpResponse.expectedContentLength != NSURLResponseUnknownLength) + Res.Size = httpResponse.expectedContentLength; + NSString *dateModified = httpResponse.allHeaderFields[@"Date"]; + if (dateModified){ + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en"]]; + [formatter setDateFormat:@"EEEE, dd LLL yyyy HH:mm:ss zzz"]; + NSDate *date = [formatter dateFromString:dateModified]; + this->FailTime = [date timeIntervalSince1970]; + [formatter release]; + } + success = YES; + } else { + success = NO; + } + dispatch_semaphore_signal(sem); + }] resume]; + + Status(_("Connecting to %s"), Get.Host.c_str()); + dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, TimeOut * NSEC_PER_SEC)); + + // Get the files information + if (!success) + { + return false; + } + + // See if it is an IMS hit + if (Itm->LastModified == FailTime) { + Res.Size = 0; + Res.IMSHit = true; + URIDone(Res); + return true; + } + + // See if the file exists + struct stat Buf; + if (stat(Itm->DestFile.c_str(),&Buf) == 0) { + if (Res.Size == (unsigned long long)Buf.st_size && FailTime == Buf.st_mtime) { + Res.Size = Buf.st_size; + Res.LastModified = Buf.st_mtime; + Res.ResumePoint = Buf.st_size; + URIDone(Res); + return true; + } + + // Resume? + if (FailTime == Buf.st_mtime && Res.Size > (unsigned long long)Buf.st_size) + Res.ResumePoint = Buf.st_size; + } + + // Open the file + Hashes Hash(Itm->ExpectedHashes); + { + [request setHTTPMethod:@"GET"]; + + success = NO; + + NSURLSessionDownloadTask *task = [[NSURLSession sharedSession] downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error){ + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; + if (httpResponse.statusCode == 200 && !error){ + NSString *destFile = [NSString stringWithUTF8String:Itm->DestFile.c_str()]; + [[NSFileManager defaultManager] removeItemAtPath:destFile error:nil]; + success = [[NSFileManager defaultManager] moveItemAtPath:location.path toPath:destFile error:&error]; + if (error){ + success = NO; + } + } + dispatch_semaphore_signal(sem); + }]; + [task resume]; + dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, TimeOut * NSEC_PER_SEC)); + + if (!success){ + Fail(true); + return true; + } + + FileFd Fd(Itm->DestFile,FileFd::WriteExists); + Hash.AddFD(Fd,Hashes::UntilEOF); + + URIStart(Res); + + Res.Size = Fd.Size(); + struct timeval times[2]; + times[0].tv_sec = FailTime; + times[1].tv_sec = FailTime; + times[0].tv_usec = times[1].tv_usec = 0; + utimes(Fd.Name().c_str(), times); + } + + Res.LastModified = FailTime; + Res.TakeHashes(Hash); + + URIDone(Res); + + return true; +} + /*}}}*/ + +int main(int, const char *argv[]) +{ + return HttpMethod(flNotDir(argv[0])).Run(); +} |