]>
git.saurik.com Git - apt.git/blob - apt-private/private-download.cc
8a57ccc869d2d21470d75c5d657f6d6fc9b56f05
1 // Include Files /*{{{*/
4 #include <apt-pkg/acquire.h>
5 #include <apt-pkg/acquire-item.h>
6 #include <apt-pkg/configuration.h>
7 #include <apt-pkg/error.h>
8 #include <apt-pkg/fileutl.h>
9 #include <apt-pkg/strutl.h>
11 #include <apt-private/private-output.h>
12 #include <apt-private/private-download.h>
19 #include <sys/types.h>
23 #include <sys/statvfs.h>
29 // CheckAuth - check if each download comes form a trusted source /*{{{*/
30 bool CheckAuth(pkgAcquire
& Fetcher
, bool const PromptUser
)
32 std::vector
<std::string
> UntrustedList
;
33 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
34 if (!(*I
)->IsTrusted())
35 UntrustedList
.push_back((*I
)->ShortDesc());
37 if (UntrustedList
.empty())
40 return AuthPrompt(UntrustedList
, PromptUser
);
43 bool AuthPrompt(std::vector
<std::string
> const &UntrustedList
, bool const PromptUser
)
45 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"), UntrustedList
,
46 [](std::string
const&) { return true; },
47 [](std::string
const&str
) { return str
; },
48 [](std::string
const&) { return ""; });
50 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
52 c2out
<< _("Authentication warning overridden.\n");
56 if (PromptUser
== false)
57 return _error
->Error(_("Some packages could not be authenticated"));
59 if (_config
->FindI("quiet",0) < 2
60 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
62 c2out
<< _("Install these packages without verification?") << std::flush
;
64 return _error
->Error(_("Some packages could not be authenticated"));
68 else if (_config
->FindB("APT::Get::Force-Yes",false) == true) {
69 _error
->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead."));
73 return _error
->Error(_("There were unauthenticated packages and -y was used without --allow-unauthenticated"));
76 bool AcquireRun(pkgAcquire
&Fetcher
, int const PulseInterval
, bool * const Failure
, bool * const TransientNetworkFailure
)/*{{{*/
78 pkgAcquire::RunResult res
;
80 res
= Fetcher
.Run(PulseInterval
);
84 if (res
== pkgAcquire::Failed
)
87 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin();
88 I
!= Fetcher
.ItemsEnd(); ++I
)
91 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
92 (*I
)->Complete
== true)
95 if (TransientNetworkFailure
!= NULL
&& (*I
)->Status
== pkgAcquire::Item::StatIdle
)
97 *TransientNetworkFailure
= true;
101 ::URI
uri((*I
)->DescURI());
103 uri
.Password
.clear();
104 std::string descUri
= std::string(uri
);
105 _error
->Error(_("Failed to fetch %s %s\n"), descUri
.c_str(),
106 (*I
)->ErrorText
.c_str());
115 bool CheckFreeSpaceBeforeDownload(std::string
const &Dir
, unsigned long long FetchBytes
)/*{{{*/
117 uint32_t const RAMFS_MAGIC
= 0x858458f6;
118 /* Check for enough free space, but only if we are actually going to
120 if (_config
->FindB("APT::Get::Print-URIs", false) == true ||
121 _config
->FindB("APT::Get::Download", true) == false)
125 if (statvfs(Dir
.c_str(),&Buf
) != 0) {
126 if (errno
== EOVERFLOW
)
127 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
130 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
135 unsigned long long const FreeBlocks
= _config
->Find("APT::Sandbox::User").empty() ? Buf
.f_bfree
: Buf
.f_bavail
;
136 if (FreeBlocks
< (FetchBytes
/ Buf
.f_bsize
))
139 if (statfs(Dir
.c_str(),&Stat
) != 0
140 #if HAVE_STRUCT_STATFS_F_TYPE
141 || Stat
.f_type
!= RAMFS_MAGIC
144 return _error
->Error(_("You don't have enough free space in %s."),