"apt-file update" downloads the whole Contents file every time

Bug #2502 reported by Chris Moore
8
Affects Status Importance Assigned to Milestone
apt-file (Ubuntu)
Fix Released
Medium
MOTU

Bug Description

The 'http' definition in /etc/apt/apt-file.conf says this:

  http = wget -N -P "<cache>" -O "<cache>/<dest>" "<uri>/dists/<dist>/Contents-<arch>.gz" || rm -f "<cache>/<dest>";

The -N is supposed to turn on timestamping, so that the file is only downloaded if it has changed on the server. However, -N doesn't work if -O is also specified, and so the whole download is down each time.

It would be better to leave out the -O flag so that timestamping can work.

The problem is that the local file and the file on the server have different names. To get timestamping to work, they have to have the same name. We can rename the local file before running wget and rename it back after, like this:

  http = (if [ -f "<cache>/<dest>" ]; then mv "<cache>/<dest>" "<cache>/Contents-<arch>.gz"; fi; wget -N -P "<cache>" "<uri>/dists/<dist>/Contents-<arch>.gz" 2>&1 && mv "<cache>/Contents-<arch>.gz" "<cache>/<dest>" || rm -f "<cache>/<dest>") | grep -v -e "^--" -e "=>" -e "^Length:" -e "^HTTP" -e "^Resolving" -e "^Connecting" -e "ERROR 404" 1>&2

That line also filters out a lot of the output from wget, but leaves the progress display in place. The current version shows this:

--20:10:04-- http://archive.ubuntu.com/ubuntu/dists/breezy-security/Contents-i386.gz
           => `/var/cache/apt/archive.ubuntu.com_ubuntu_dists_breezy-security_Contents-i386.gz'
Resolving archive.ubuntu.com... 82.211.81.151, 82.211.81.182
Connecting to archive.ubuntu.com|82.211.81.151|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
20:10:05 ERROR 404: Not Found.

for files which don't exist on the server. My version above shows nothing for the missing files, the same as the curl line, and shows this:

  Server file no newer than local file `/var/cache/apt/Contents-i386.gz' -- not retrieving.

as confirmation that the server file exists but hasn't changed.

Revision history for this message
Chris Moore (dooglus) wrote :

Note that the "ftp =" line also tries to combine the -N and -O options, and so probably fails in the same way.

Revision history for this message
Stephan Rügamer (sruegamer) wrote :

thx for this detailed fix/patch. I will incorporate it into a new upload..

Think it will be available tomorrow...time to go to bed for me :)

Regards,

\sh

Revision history for this message
Chris Moore (dooglus) wrote : replacement apt-file.conf

This is a replacement /etc/apt/apt-file.conf with changes made for both HTTP and FTP. wget will only download now if the file has changed on the server, whereas the previous version downloads the whole file every time, due to -N not working when -O is specified to wget.

Revision history for this message
Stephan Rügamer (sruegamer) wrote :

Thx,

I uploaded a new version yesterday evening...please test.

Revision history for this message
Chris Moore (dooglus) wrote :

I saw your new version. It works, but is a big messy when using FTP:

------
chris@chrislap:~$ sudo apt-file update
Password:
Logging in as anonymous ... Logged in!

    0K 12.24 MB/s

12:23:35 (12.24 MB/s) - `/var/cache/apt/.listing' saved [398]

Removed `/var/cache/apt/.listing'.
No such file `Contents-i386.gz'.

Logging in as anonymous ... Logged in!

    0K 524.22 KB/s

12:23:37 (524.22 KB/s) - `/var/cache/apt/.listing' saved [773]

Removed `/var/cache/apt/.listing'.
Remote file no newer than local file `/var/cache/apt/Contents-i386.gz' -- not retrieving.
chris@chrislap:~$
------

If you use the apt-file.conf which I attached last night you'll not see those extra lines. I basically just edited the 'grep -v' arguments to cater for the slightly different output when wget is doing FTP access rather than HTTP access.

Revision history for this message
Chris Moore (dooglus) wrote :

A *bit* messy, I meant, not "a big messy".

Changed in apt-file:
assignee: nobody → motu
Revision history for this message
Stephan Rügamer (sruegamer) wrote :

Uploaded and tested with your new changes. Looks good now :)

Thx,

\sh

Changed in apt-file:
status: New → Fixed
Revision history for this message
Chris Moore (dooglus) wrote :

My only remaining complaints would be with the line that says "# If you prefere wget uncomment following", namely:

1) that's not how you spell "prefer".

2) the lines it refers to are now uncommented already, so the instruction to uncomment them is less than clear.

The file I attached above fixes both these problems.

Revision history for this message
Stephan Rügamer (sruegamer) wrote :

Fixed the spelling typo in last upload

Revision history for this message
Chris Moore (dooglus) wrote :

You wrote 'curl' where you should have written 'wget' in that last update.

At the risk of repeating myself, I made an attachment to this bug with a correct apt-file.conf in it, here:

  http://librarian.launchpad.net/430661/430694/apt-file.conf

Revision history for this message
Daniel Holbach (dholbach) wrote :

Sorry Sascha Hölterhoff, I added you as CC by mistake. :-(

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.