Commit Graph

92 Commits

Author SHA1 Message Date
David Kalnischkies 258b9e512c apply various suggestions made by cppcheck
Reported-By: cppcheck
Git-Dch: Ignore
2015-11-05 12:21:33 +01:00
David Kalnischkies ce1f3a2c61 wrap every unlink call to check for != /dev/null
Unlinking /dev/null is bad, we shouldn't do that. Also, we should print
at least a warning if we tried to unlink a file but didn't manage to
pull it of (ignoring the case were the file is /dev/null or doesn't
exist in the first place).

This got triggered by a relatively unlikely to cause problem in
pkgAcquire::Worker::PrepareFiles which would while temporary
uncompressed files (which are set to keep compressed) figure out that to
files are the same and prepare for sharing by deleting them. Bad move.
That also shows why not printing a warning is a bad idea as this hide
the error for in non-root test runs.

Git-Dch: Ignore
2015-11-04 18:42:28 +01:00
David Kalnischkies bce8e59b81 set failreasons similar to connect.cc based on curl errors
Detecting network errors has some benefits in the acquire system as if
we can't connect to a host trying it for a million files is pointless.
http and co which use connect.cc deal with this, but https which uses
curl had connection failures as "normal" errors which could potentially
be worked around (like trying Release instead of the failed InRelease).

Git-Dch: Ignore
2015-11-04 18:04:01 +01:00
David Kalnischkies 830a1b8c9e fix two memory leaks reported by gcc
Reported-By: gcc -fsanitize=address -fno-sanitize=vptr
Git-Dch: Ignore
2015-09-14 15:22:18 +02:00
Michael Vogt 4fc6b7570c Merge branch 'debian/sid' into debian/experimental
Conflicts:
	apt-pkg/pkgcache.h
	debian/changelog
	methods/https.cc
	methods/server.cc
	test/integration/test-apt-download-progress
2015-05-22 17:01:03 +02:00
Michael Vogt 65759e00ef Update methods/https.cc now that ServerState::Size is renamed
Git-Dch: ignore
2015-05-22 16:30:29 +02:00
Michael Vogt 0f3150e704 Merge remote-tracking branch 'upstream/debian/jessie' into debian/sid
Conflicts:
	apt-pkg/deb/dpkgpm.cc
2015-05-22 16:17:08 +02:00
Michael Vogt 6291f60e86 Rename "Size" in ServerState to TotalFileSize
The variable "Size" was misleading and caused bug #1445239. To
avoid similar issues in the future, rename it to make the meaning
more obvious.

git-dch: ignore
2015-05-22 15:40:18 +02:00
David Kalnischkies 8eafc75954 detect Releasefile IMS hits even if the server doesn't
Not all servers we are talking to support If-Modified-Since and some are
not even sending Last-Modified for us, so in an effort to detect such
hits we run a hashsum check on the 'old' compared to the 'new' file, we
got the hashes for the 'new' already for "free" from the methods anyway
and hence just need to calculated the old ones.

This allows us to detect hits even with unsupported servers, which in
turn means we benefit from all the new hit behavior also here.
2015-05-13 16:09:12 +02:00
David Kalnischkies dcbb364fc6 detect 416 complete file in partial by expected hash
If we have the expected hashes we can check with them if the file we
have in partial we got a 416 for is the expected file. We detected this
with same-size before, but not every server sends a good Content-Range
header with a 416 response.
2015-05-12 00:30:16 +02:00
David Kalnischkies 34faa8f7ae calculate hashes while downloading in https
We do this in HTTP already to give the CPU some exercise while the disk
is heavily spinning (or flashing?) to store the data avoiding the need
to reread the entire file again later on to calculate the hashes – which
happens outside of the eyes of progress reporting, so you might ended up
with a bunch of https workers 'stuck' at 100% while they were busy
calculating hashes.

This is a bummer for everyone using apt as a connection speedtest as the
https method works slower now (not really, it just isn't reporting done
too early anymore).
2015-04-19 01:13:09 +02:00
David Kalnischkies 9224ce3d4d calculate only expected hashes in methods
Methods get told which hashes are expected by the acquire system, which
means we can use this list to restrict what we calculate in the methods
as any extra we are calculating is wasted effort as we can't compare it
with anything anyway.

Adding support for a new hash algorithm is therefore 'free' now and if a
algorithm is no longer provided in a repository for a file, we
automatically stop calculating it.

In practice this results in a speed-up in Debian as we don't have SHA512
here (so far), so we practically stop calculating it.
2015-04-19 01:13:09 +02:00
David Kalnischkies 27925d82dd improve https method queue progress reporting
The worker expects that the methods tell him when they start or finish
downloading a file. Various information pieces are passed along in this
report including the (expected) filesize. https was using a "global"
struct for reporting which made it 'reuse' incorrect values in some
cases like a non-existent InRelease fallbacking to Release{,.gpg}
resulting in a size-mismatch warning. Reducing the scope and redesigning
the setting of the values we can fix this and related issues.

Closes: 777565, 781509
Thanks: Robert Edmonds and Anders Kaseorg for initial patchs
2015-04-19 01:13:08 +02:00
David Kalnischkies bb948ef562 do not unlink https file on general error
It might be quite interesting which file (content) made curl freak out
and other methods keep the file around as well.

Git-Dch: Ignore
2015-04-19 01:13:08 +02:00
Michael Vogt 3a53f6a151 Revert "HttpsMethod::Fetch(): Zero the FetchResult object when leaving due to 404"
This reverts commit 1296bc7c46.
2015-04-13 12:57:22 -04:00
David Kalnischkies a2679f55b5 properly handle expected filesize in https
The worker expects that the methods tell him when they start or finish
downloading a file. Various information pieces are passed along in this report
including the (expected) filesize. https is using a "global" struct for
reporting which made it 'reuse' incorrect values in some cases like a
non-existent InRelease fallbacking to Release{,.gpg} resulting in an incorrect
size-mismatch warning scaring and desensitizing users as well as being subject
to a race between the write_data and progress callbacks generating incorrect
progress reporting and potentially the same error message.

Other branches as well as the bugreports contain 'better' fixes making the
struct local and other sensible changes, but are larger as a result, so in
this version we opted for short diff with minimal effect above else instead.

Closes: 777565, 781509
Thanks: Robert Edmonds and Anders Kaseorg for initial patchs
2015-04-07 17:20:35 +02:00
Robert Edmonds 1296bc7c46 HttpsMethod::Fetch(): Zero the FetchResult object when leaving due to 404 2015-04-07 12:23:51 +02:00
David Kalnischkies 905fba60a0 derive more of https from http method
Bug #778375 uncovered that https wasn't properly integrated in the class
family tree of http as it was supposed to be leading to a NULL pointer
dereference. Fixing this 'properly' was deemed to much diff for
practically no gain that late in the release, so commit
0c2dc43d4f just fixed the synptom, while
this commit here is fixing the cause plus adding a test.
2015-03-16 18:00:50 +01:00
David Kalnischkies d61960d924 merge debian/sid into debian/experimental 2015-03-16 17:59:31 +01:00
Michael Vogt 9127d7aecf Fix missing URIStart() for https downloads
Add a explicit ReceivedData to HttpsMethod that indicates when
we got data from the connection so that we can send URISTart()
to the parent.

This is needed because URIStart got moved in f9b4f12d from
the progress_callback to write_data() and it only checks for
Res.Size. In the old code if progress_callback is called by
libcurl (and sets Res.Size) before write_data is called then
URIStart() is never send. Making this a explicit ReceivedData
variable fixes this issue.
2015-01-05 10:27:53 +01:00
David Kalnischkies 92e8c1ff28 dispose http(s) 416 error page as non-content
Real webservers (like apache) actually send an error page with a 416
response, but our client didn't expect it leaving the page on the socket
to be parsed as response for the next request (http) or as file content
(https), which isn't what we want at all… Symptom is a "Bad header line"
as html usually doesn't parse that well to an http-header.

This manifests itself e.g. if we have a complete file (or larger) in
partial/ which isn't discarded by If-Range as the server doesn't support
it (or it is just newer, think: mirror rotation).
It is a sort-of regression of 78c72d0ce2,
which removed the filesize - 1 trick, but this had its own problems…

To properly test this our webserver gains the ability to reply with
transfer-encoding: chunked as most real webservers will use it to send
the dynamically generated error pages.

(The tests and their binary helpers had to be slightly modified to
apply, but the patch to fix the issue itself is unchanged.)

Closes: 768797
2014-12-22 14:23:39 +01:00
David Kalnischkies ed793a19ec dispose http(s) 416 error page as non-content
Real webservers (like apache) actually send an error page with a 416
response, but our client didn't expect it leaving the page on the socket
to be parsed as response for the next request (http) or as file content
(https), which isn't what we want at all… Symptom is a "Bad header line"
as html usually doesn't parse that well to an http-header.

This manifests itself e.g. if we have a complete file (or larger) in
partial/ which isn't discarded by If-Range as the server doesn't support
it (or it is just newer, think: mirror rotation).
It is a sort-of regression of 78c72d0ce2,
which removed the filesize - 1 trick, but this had its own problems…

To properly test this our webserver gains the ability to reply with
transfer-encoding: chunked as most real webservers will use it to send
the dynamically generated error pages.

Closes: 768797
2014-12-09 01:13:48 +01:00
Michael Vogt 9983999d29 Fix backward compatiblity of the new pkgAcquireMethod::DropPrivsOrDie()
Do not drop privileges in the methods when using a older version of
libapt that does not support the chown magic in partial/ yet. To
do this DropPrivileges() now will ignore a empty Apt::Sandbox::User.

Cleanup all hardcoded _apt along the way.
2014-10-13 11:29:47 +02:00
Michael Vogt ee27950632 Send "Fail-Reason: MaximumSizeExceeded" from the method
Communicate the fail reason from the methods to the parent
and Rename() failed files.
2014-10-07 22:36:09 +02:00
Michael Vogt c48eea97b9 make expected-size a maximum-size check as this is what we want at this point 2014-10-07 17:47:30 +02:00