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 /apt-private | |
parent | 713b65be84830af1a57148b44dc1d1d4010ece3e (diff) |
1.8.0-Sileosille-apt
Diffstat (limited to 'apt-private')
-rw-r--r-- | apt-private/CMakeLists.txt | 4 | ||||
-rw-r--r-- | apt-private/private-output.mm (renamed from apt-private/private-output.cc) | 284 |
2 files changed, 152 insertions, 136 deletions
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 /*{{{*/ |