X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/51c4e07f4cba0615ff269b5a8d04dfd3d1313b00..2b0660b537581e9e65180e4cf1a94d763fd66847:/cmdline/apt-get.cc?ds=sidebyside diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 61ed41164..2a19360c8 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -78,7 +78,6 @@ #include #include #include -#include #include #include #include @@ -596,14 +595,12 @@ static bool DoDownload(CommandLine &CmdL) if (verset.empty() == true) return false; - AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0)); - pkgAcquire Fetcher(&Stat); - pkgRecords Recs(Cache); pkgSourceList *SrcList = Cache.GetSourceList(); // reuse the usual acquire methods for deb files, but don't drop them into // the usual directories - keep everything in the current directory + aptAcquireWithTextStatus Fetcher; std::vector storefile(verset.size()); std::string const cwd = SafeGetCWD(); _config->Set("Dir::Cache::Archives", cwd); @@ -629,9 +626,6 @@ static bool DoDownload(CommandLine &CmdL) return true; } - // Disable drop-privs if "_apt" can not write to the target dir - CheckDropPrivsMustBeDisabled(Fetcher); - if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false) return false; @@ -697,10 +691,6 @@ static bool DoSource(CommandLine &CmdL) if (_error->PendingError() == true) return false; - // Create the download object - AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0)); - pkgAcquire Fetcher(&Stat); - std::unique_ptr Dsc(new DscFile[CmdL.FileSize()]); // insert all downloaded uris into this set to avoid downloading them @@ -715,6 +705,7 @@ static bool DoSource(CommandLine &CmdL) bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false); // Load the requestd sources into the fetcher + aptAcquireWithTextStatus Fetcher; unsigned J = 0; std::vector UntrustedList; for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) @@ -741,17 +732,22 @@ static bool DoSource(CommandLine &CmdL) } pos += vcs.length()+2; string::size_type epos = srec.find("\n", pos); - string uri = srec.substr(pos,epos-pos).c_str(); + string const uri = srec.substr(pos,epos-pos); ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in " "the '%s' version control system at:\n" "%s\n"), Src.c_str(), vcs.c_str(), uri.c_str()); - if(vcs == "Bzr") - ioprintf(c1out,_("Please use:\n" - "bzr branch %s\n" - "to retrieve the latest (possibly unreleased) " - "updates to the package.\n"), - uri.c_str()); + std::string vcscmd; + if (vcs == "Bzr") + vcscmd = "bzr branch " + uri; + else if (vcs == "Git") + vcscmd = "git clone " + uri; + + if (vcscmd.empty() == false) + ioprintf(c1out,_("Please use:\n%s\n" + "to retrieve the latest (possibly unreleased) " + "updates to the package.\n"), + vcscmd.c_str()); break; } @@ -850,9 +846,6 @@ static bool DoSource(CommandLine &CmdL) return true; } - // Disable drop-privs if "_apt" can not write to the target dir - CheckDropPrivsMustBeDisabled(Fetcher); - // check authentication status of the source as well if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false) return false; @@ -942,19 +935,7 @@ static bool DoSource(CommandLine &CmdL) _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"); - } - - if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) - return _error->Error(_("Child process failed")); - - return true; + return ExecWait(Process, "dpkg-source"); } /*}}}*/ // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/ @@ -966,8 +947,10 @@ static bool DoBuildDep(CommandLine &CmdL) CacheFile Cache; _config->Set("APT::Install-Recommends", false); + + bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false; - if (Cache.Open(true) == false) + if (Cache.Open(WantLock) == false) return false; if (CmdL.FileSize() <= 1) @@ -1380,13 +1363,11 @@ static bool DoChangelog(CommandLine &CmdL) CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper); if (verset.empty() == true) return false; - pkgAcquire Fetcher; - AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0)); - Fetcher.SetLog(&Stat); bool const downOnly = _config->FindB("APT::Get::Download-Only", false); bool const printOnly = _config->FindB("APT::Get::Print-URIs", false); + aptAcquireWithTextStatus Fetcher; for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) @@ -1401,11 +1382,6 @@ static bool DoChangelog(CommandLine &CmdL) if (printOnly == false) { - // Disable drop-privs if "_apt" can not write to the target dir - CheckDropPrivsMustBeDisabled(Fetcher); - if (_error->PendingError() == true) - return false; - bool Failed = false; if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true) return false; @@ -1496,11 +1472,21 @@ static bool DoIndexTargets(CommandLine &CmdL) << "Description: " << T->Description << "\n" << "URI: " << T->URI << "\n" << "Filename: " << filename << "\n" - << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n"; + << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n" + << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n"; for (std::map::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O) stanza << format_key(O->first) << ": " << O->second << "\n"; for (std::map::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O) - stanza << format_key(O->first) << ": " << O->second << "\n"; + { + if (O->first == "PDIFFS") + stanza << "PDiffs: " << O->second << "\n"; + else if (O->first == "COMPRESSIONTYPES") + stanza << "CompressionTypes: " << O->second << "\n"; + else if (O->first == "DEFAULTENABLED") + stanza << "DefaultEnabled: " << O->second << "\n"; + else + stanza << format_key(O->first) << ": " << O->second << "\n"; + } stanza << "\n"; if (Filtered) @@ -1543,7 +1529,7 @@ static bool DoIndexTargets(CommandLine &CmdL) // ShowHelp - Show a help screen /*{{{*/ // --------------------------------------------------------------------- /* */ -static bool ShowHelp(CommandLine &) +static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) { ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -1588,34 +1574,26 @@ static bool ShowHelp(CommandLine &) return true; } - - cout << + + std::cout << _("Usage: apt-get [options] command\n" " apt-get [options] install|remove pkg1 [pkg2 ...]\n" " apt-get [options] source pkg1 [pkg2 ...]\n" "\n" "apt-get is a simple command line interface for downloading and\n" "installing packages. The most frequently used commands are update\n" - "and install.\n" - "\n" - "Commands:\n" - " update - Retrieve new lists of packages\n" - " upgrade - Perform an upgrade\n" - " install - Install new packages (pkg is libc6 not libc6.deb)\n" - " remove - Remove packages\n" - " autoremove - Remove automatically all unused packages\n" - " purge - Remove packages and config files\n" - " source - Download source archives\n" - " build-dep - Configure build-dependencies for source packages\n" - " dist-upgrade - Distribution upgrade, see apt-get(8)\n" - " dselect-upgrade - Follow dselect selections\n" - " clean - Erase downloaded archive files\n" - " autoclean - Erase old downloaded archive files\n" - " check - Verify that there are no broken dependencies\n" - " changelog - Download and display the changelog for the given package\n" - " download - Download the binary package into the current directory\n" - "\n" - "Options:\n" + "and install.\n") + << std::endl + << _("Commands:") << std::endl; + for (; Cmds->Handler != nullptr; ++Cmds) + { + if (Cmds->Help == nullptr) + continue; + std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl; + } + + std::cout << std::endl << + _("Options:\n" " -h This help text.\n" " -q Loggable output - no progress indicator\n" " -qq No output except for errors\n" @@ -1637,56 +1615,43 @@ static bool ShowHelp(CommandLine &) /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ { - CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, - {"upgrade",&DoUpgrade}, - {"install",&DoInstall}, - {"remove",&DoInstall}, - {"purge",&DoInstall}, - {"autoremove",&DoInstall}, - {"markauto",&DoMarkAuto}, - {"unmarkauto",&DoMarkAuto}, - {"dist-upgrade",&DoDistUpgrade}, - {"dselect-upgrade",&DoDSelectUpgrade}, - {"build-dep",&DoBuildDep}, - {"clean",&DoClean}, - {"autoclean",&DoAutoClean}, - {"check",&DoCheck}, - {"source",&DoSource}, - {"download",&DoDownload}, - {"changelog",&DoChangelog}, - {"indextargets",&DoIndexTargets}, - {"moo",&DoMoo}, - {"help",&ShowHelp}, - {0,0}}; - - std::vector Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv)); - - // Set up gettext support - setlocale(LC_ALL,""); - textdomain(PACKAGE); + InitLocale(); + + CommandLine::DispatchWithHelp Cmds[] = { + {"update", &DoUpdate, _("Retrieve new lists of packages")}, + {"upgrade", &DoUpgrade, _("Perform an upgrade")}, + {"install", &DoInstall, _("Install new packages (pkg is libc6 not libc6.deb)")}, + {"remove", &DoInstall, _("Remove packages")}, + {"purge", &DoInstall, _("Remove packages and config files")}, + {"autoremove", &DoInstall, _("Remove automatically all unused packages")}, + {"auto-remove", &DoInstall, nullptr}, + {"markauto", &DoMarkAuto, nullptr}, + {"unmarkauto", &DoMarkAuto, nullptr}, + {"dist-upgrade", &DoDistUpgrade, _("Distribution upgrade, see apt-get(8)")}, + {"full-upgrade", &DoDistUpgrade, nullptr}, + {"dselect-upgrade", &DoDSelectUpgrade, _("Follow dselect selections")}, + {"build-dep", &DoBuildDep, _("Configure build-dependencies for source packages")}, + {"clean", &DoClean, _("Erase downloaded archive files")}, + {"autoclean", &DoAutoClean, _("Erase old downloaded archive files")}, + {"auto-clean", &DoAutoClean, nullptr}, + {"check", &DoCheck, _("Verify that there are no broken dependencies")}, + {"source", &DoSource, _("Download source archives")}, + {"download", &DoDownload, _("Download the binary package into the current directory")}, + {"changelog", &DoChangelog, _("Download and display the changelog for the given package")}, + {"indextargets", &DoIndexTargets, nullptr}, + {"moo", &DoMoo, nullptr}, + {nullptr, nullptr, nullptr} + }; // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp); + ParseCommandLine(CmdL, Cmds, "apt-get", &_config, &_system, argc, argv, ShowHelp); - // see if we are in simulate mode - CheckSimulateMode(CmdL); - - // Init the signals InitSignals(); - - // Setup the output streams InitOutput(); - // Match the operation - CmdL.DispatchArg(Cmds); + CheckIfSimulateMode(CmdL); - // Print any errors or warnings found during parsing - bool const Errors = _error->PendingError(); - if (_config->FindI("quiet",0) > 0) - _error->DumpErrors(); - else - _error->DumpErrors(GlobalError::DEBUG); - return Errors == true ? 100 : 0; + return DispatchCommandLine(CmdL, Cmds); } /*}}}*/