]>
git.saurik.com Git - apt.git/blob - apt-private/private-download.cc
96d44b1c5c88a9bad53d84458e893570301d6a10
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>
13 #include <apt-private/acqprogress.h>
20 #include <sys/types.h>
24 #include <sys/statvfs.h>
30 // CheckAuth - check if each download comes form a trusted source /*{{{*/
31 bool CheckAuth(pkgAcquire
& Fetcher
, bool const PromptUser
)
33 std::vector
<std::string
> UntrustedList
;
34 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
35 if (!(*I
)->IsTrusted())
36 UntrustedList
.push_back((*I
)->ShortDesc());
38 if (UntrustedList
.empty())
41 return AuthPrompt(UntrustedList
, PromptUser
);
44 bool AuthPrompt(std::vector
<std::string
> const &UntrustedList
, bool const PromptUser
)/*{{{*/
46 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"), UntrustedList
,
47 [](std::string
const&) { return true; },
48 [](std::string
const&str
) { return str
; },
49 [](std::string
const&) { return ""; });
51 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
53 c2out
<< _("Authentication warning overridden.\n");
57 if (PromptUser
== false)
58 return _error
->Error(_("Some packages could not be authenticated"));
60 if (_config
->FindI("quiet",0) < 2
61 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
63 c2out
<< _("Install these packages without verification?") << std::flush
;
65 return _error
->Error(_("Some packages could not be authenticated"));
69 else if (_config
->FindB("APT::Get::Force-Yes",false) == true) {
70 _error
->Warning(_("--force-yes is deprecated, use one of the options starting with --allow instead."));
74 return _error
->Error(_("There were unauthenticated packages and -y was used without --allow-unauthenticated"));
77 bool AcquireRun(pkgAcquire
&Fetcher
, int const PulseInterval
, bool * const Failure
, bool * const TransientNetworkFailure
)/*{{{*/
79 pkgAcquire::RunResult res
;
81 res
= Fetcher
.Run(PulseInterval
);
85 if (res
== pkgAcquire::Failed
)
88 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin();
89 I
!= Fetcher
.ItemsEnd(); ++I
)
92 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
93 (*I
)->Complete
== true)
96 if (TransientNetworkFailure
!= NULL
&& (*I
)->Status
== pkgAcquire::Item::StatIdle
)
98 *TransientNetworkFailure
= true;
102 ::URI
uri((*I
)->DescURI());
104 uri
.Password
.clear();
105 std::string descUri
= std::string(uri
);
106 _error
->Error(_("Failed to fetch %s %s\n"), descUri
.c_str(),
107 (*I
)->ErrorText
.c_str());
116 bool CheckFreeSpaceBeforeDownload(std::string
const &Dir
, unsigned long long FetchBytes
)/*{{{*/
118 uint32_t const RAMFS_MAGIC
= 0x858458f6;
119 /* Check for enough free space, but only if we are actually going to
121 if (_config
->FindB("APT::Get::Print-URIs", false) == true ||
122 _config
->FindB("APT::Get::Download", true) == false)
126 if (statvfs(Dir
.c_str(),&Buf
) != 0) {
127 if (errno
== EOVERFLOW
)
128 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
131 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
136 unsigned long long const FreeBlocks
= _config
->Find("APT::Sandbox::User").empty() ? Buf
.f_bfree
: Buf
.f_bavail
;
137 if (FreeBlocks
< (FetchBytes
/ Buf
.f_bsize
))
140 if (statfs(Dir
.c_str(),&Stat
) != 0
141 #if HAVE_STRUCT_STATFS_F_TYPE
142 || Stat
.f_type
!= RAMFS_MAGIC
145 return _error
->Error(_("You don't have enough free space in %s."),
153 aptAcquireWithTextStatus::aptAcquireWithTextStatus() : pkgAcquire::pkgAcquire(),
154 Stat(std::cout
, ScreenWidth
, _config
->FindI("quiet",0))