Package: ftp.debian.org
Severity: normal

I've recently injected in http://sources.debian.net all source packages coming
from hitorical releases stored at http://archive.debian.org --- so thank a
bunch for the service!

While doing so, I've discovered that 67 source packages mentioned in Debian 2.2
'potato' Sources.gz aren't available at their expected location. Here is an
example:

http://archive.debian.org/debian/dists/Debian-2.2/main/source/Sources.gz
contains the following paragraph about makepasswd/1.10-1:

  Package: makepasswd
  Binary: makepasswd
  Version: 1.10-1
  Priority: optional
  Section: admin
  Maintainer: Johnie Ingram <joh...@debian.org>
  Architecture: all
  Standards-Version: 3.0.1.0
  Directory: dists/potato/main/source/admin
  Files:
   a778640306e45f1166f28631486eb43e 628 makepasswd_1.10-1.dsc
   55842bb4c064ebcdedffb4afd5f0945a 12382 makepasswd_1.10.orig.tar.gz
   1112703e7f1e0462a10ff22e29195330 2294 makepasswd_1.10-1.diff.gz

however, at
http://archive.debian.org/debian/dists/Debian-2.2/main/source/admin/ none of
the 3 components of the source package (.dsc, .orig.tar.gz, .diff.gz) is
present. Direct link to them return 404,
e.g. 
http://archive.debian.org/debian/dists/Debian-2.2/main/source/admin/makepasswd_1.10-1.dsc
A list of 404 links from archive.d.o can be found in the attached file
dangling-archive.d.o-links.txt .

OTOH, the files *are* present on archive.d.o under the pool/ structure; they
are simply not linked from the places referenced by Sources.gz. It looks like
some attempt to migrate potato ex-post to the pool/ structure (maybe at
archival time?) has gone badly.

Using the attached deb-dangling-sources script (live version at
http://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=contrib/deb-dangling-sources;hb=HEAD)
you can produce a report whose 4th column is a list of "ln -s ..." commands
that should fix the issue. Or, at least, that did fix the issue on my local
archive.d.o mirror :-)

Just run the script as "deb-dangling-sources /path/to/archive.d.o/root"

Note: I've only checked Sources.gz and not Packages.gz, so it is possible that
a similar problem affects binary packages. Adapting the above script to that
end should be easy.

HTH,
Cheers.
http://archive.debian.org/debian/dists/potato/contrib/source/graphics/tkxanim_0.43.orig.tar.gz
http://archive.debian.org/debian/dists/potato/contrib/source/graphics/tkxanim_0.43-5.dsc
http://archive.debian.org/debian/dists/potato/contrib/source/graphics/tkxanim_0.43-5.diff.gz
http://archive.debian.org/debian/dists/potato/contrib/source/mail/auto-pgp_1.04.orig.tar.gz
http://archive.debian.org/debian/dists/potato/contrib/source/mail/auto-pgp_1.04-4.dsc
http://archive.debian.org/debian/dists/potato/contrib/source/mail/auto-pgp_1.04-4.diff.gz
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-rablpc8k_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-rablpc8k_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-rablpc8k_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-rablpc16k_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-rablpc16k_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-rablpc16k_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-don_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-don_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/contrib/source/sound/festvox-don_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/ttysnoop_0.12c.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/ttysnoop_0.12c-7.dsc
http://archive.debian.org/debian/dists/potato/main/source/admin/ttysnoop_0.12c-7.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/super_3.12.2.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/super_3.12.2-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/admin/super_3.12.2-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/makepasswd_1.10.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/makepasswd_1.10-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/admin/makepasswd_1.10-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/gnosamba_0.3.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/admin/gnosamba_0.3.3-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/admin/gnosamba_0.3.3-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/comm/hylafax_4.0.2.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/comm/hylafax_4.0.2-14.dsc
http://archive.debian.org/debian/dists/potato/main/source/comm/hylafax_4.0.2-14.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/xmake_1.05.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/xmake_1.05-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/devel/xmake_1.05-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/rcs_5.7.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/rcs_5.7-13.dsc
http://archive.debian.org/debian/dists/potato/main/source/devel/rcs_5.7-13.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/ratfor_1.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/ratfor_1.0-7.dsc
http://archive.debian.org/debian/dists/potato/main/source/devel/ratfor_1.0-7.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/p2c_1.21alpha2.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/p2c_1.21alpha2-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/devel/p2c_1.21alpha2-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/mm_1.0.11.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/mm_1.0.11-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/devel/mm_1.0.11-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/fda_1.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/devel/fda_1.0-3.dsc
http://archive.debian.org/debian/dists/potato/main/source/devel/fda_1.0-3.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/doc/haskell-doc_19991028.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/doc/haskell-doc_19991028-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/doc/haskell-doc_19991028-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/doc/festival-doc_1.4.0.1.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/doc/festival-doc_1.4.0.1-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/doc/festival-doc_1.4.0.1-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/xsol_0.31.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/xsol_0.31-3.1.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/xsol_0.31-3.1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/xdigger_1.0.10.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/xdigger_1.0.10-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/xdigger_1.0.10-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/xbl_1.0i.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/xbl_1.0i-7.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/xbl_1.0i-7.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/slashem_0.0.5E7.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/slashem_0.0.5E7-3.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/slashem_0.0.5E7-3.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/purity_1.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/purity_1-9.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/purity_1-9.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/nethack_3.3.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/nethack_3.3.0-7.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/nethack_3.3.0-7.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/games/jnethack_1.1.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/games/jnethack_1.1.3-4.dsc
http://archive.debian.org/debian/dists/potato/main/source/games/jnethack_1.1.3-4.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/graphics/scansort_1.81.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/graphics/scansort_1.81-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/graphics/scansort_1.81-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/graphics/sane_1.0.1-1999-10-21.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/graphics/sane_1.0.1-1999-10-21-12.dsc
http://archive.debian.org/debian/dists/potato/main/source/graphics/sane_1.0.1-1999-10-21-12.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/graphics/gnome-gv_0.82.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/graphics/gnome-gv_0.82-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/graphics/gnome-gv_0.82-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/interpreters/perl-5.005_5.005.03.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/interpreters/perl-5.005_5.005.03-7.1.dsc
http://archive.debian.org/debian/dists/potato/main/source/interpreters/perl-5.005_5.005.03-7.1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/interpreters/perl-5.004_5.004.05.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/interpreters/perl-5.004_5.004.05-6.dsc
http://archive.debian.org/debian/dists/potato/main/source/interpreters/perl-5.004_5.004.05-6.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/interpreters/kaffe_1.0.5e.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/interpreters/kaffe_1.0.5e-0.5.dsc
http://archive.debian.org/debian/dists/potato/main/source/interpreters/kaffe_1.0.5e-0.5.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/libs/libpng_1.0.5.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/libs/libpng_1.0.5-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/libs/libpng_1.0.5-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/libs/libgd-gif_1.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/libs/libgd-gif_1.3-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/libs/libgd-gif_1.3-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/mail/sendmail_8.9.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/mail/sendmail_8.9.3-23.dsc
http://archive.debian.org/debian/dists/potato/main/source/mail/sendmail_8.9.3-23.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/mail/mhonarc_2.4.4.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/mail/mhonarc_2.4.4-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/mail/mhonarc_2.4.4-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/mail/im_133.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/mail/im_133-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/mail/im_133-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/traceroute-nanog_6.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/traceroute-nanog_6.0-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/traceroute-nanog_6.0-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/rinetd_0.52.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/rinetd_0.52-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/rinetd_0.52-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/pptpd_1.0.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/pptpd_1.0.0-4.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/pptpd_1.0.0-4.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/nis_3.8.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/nis_3.8-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/nis_3.8-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/lpr_0.48.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/lpr_0.48-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/lpr_0.48-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/ircii-pana_1.0-0c16.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/ircii-pana_1.0-0c16-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/ircii-pana_1.0-0c16-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/icmpinfo_1.11.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/icmpinfo_1.11-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/icmpinfo_1.11-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/net/epic4_pre2.508.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/net/epic4_pre2.508-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/net/epic4_pre2.508-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/otherosfs/lpkg_19980629.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/otherosfs/lpkg_19980629-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/otherosfs/lpkg_19980629-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kdlpc16k_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kdlpc16k_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kdlpc16k_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kallpc8k_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kallpc8k_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kallpc8k_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kallpc16k_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kallpc16k_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/sound/festvox-kallpc16k_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festlex-poslex_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festlex-poslex_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/sound/festlex-poslex_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festlex-cmu_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/sound/festlex-cmu_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/sound/festlex-cmu_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/tex/tetex-bin_1.0.6.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/tex/tetex-bin_1.0.6-7.dsc
http://archive.debian.org/debian/dists/potato/main/source/tex/tetex-bin_1.0.6-7.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/text/ttfprint_0.9.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/text/ttfprint_0.9-5.dsc
http://archive.debian.org/debian/dists/potato/main/source/text/ttfprint_0.9-5.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/text/lv_4.49.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/text/lv_4.49.3-4.dsc
http://archive.debian.org/debian/dists/potato/main/source/text/lv_4.49.3-4.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/text/iportuguese_19980611.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/text/iportuguese_19980611-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/text/iportuguese_19980611-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/text/html2ps_1.0b1.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/text/html2ps_1.0b1-8.dsc
http://archive.debian.org/debian/dists/potato/main/source/text/html2ps_1.0b1-8.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/text/dict-gazetteer_1.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/text/dict-gazetteer_1.3-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/text/dict-gazetteer_1.3-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/utils/file_3.28.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/utils/file_3.28-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/utils/file_3.28-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/utils/cce_0.36.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/utils/cce_0.36-1.1.dsc
http://archive.debian.org/debian/dists/potato/main/source/utils/cce_0.36-1.1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/web/wwwoffle_2.5c.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/web/wwwoffle_2.5c-10.dsc
http://archive.debian.org/debian/dists/potato/main/source/web/wwwoffle_2.5c-10.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/web/hypermail_2.0b25.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/web/hypermail_2.0b25-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/web/hypermail_2.0b25-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/x11/xcin2.3_2.3.04.3.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/x11/xcin2.3_2.3.04.3-1.dsc
http://archive.debian.org/debian/dists/potato/main/source/x11/xcin2.3_2.3.04.3-1.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/x11/wmavgload_0.7.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/x11/wmavgload_0.7.0-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/x11/wmavgload_0.7.0-2.diff.gz
http://archive.debian.org/debian/dists/potato/main/source/x11/gwm_1.8d.orig.tar.gz
http://archive.debian.org/debian/dists/potato/main/source/x11/gwm_1.8d-2.dsc
http://archive.debian.org/debian/dists/potato/main/source/x11/gwm_1.8d-2.diff.gz
http://archive.debian.org/debian/dists/potato/non-free/source/graphics/whirlgif_3.04.orig.tar.gz
http://archive.debian.org/debian/dists/potato/non-free/source/graphics/whirlgif_3.04-1.dsc
http://archive.debian.org/debian/dists/potato/non-free/source/graphics/whirlgif_3.04-1.diff.gz
http://archive.debian.org/debian/dists/potato/non-free/source/sound/festvox-ellpc11k_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/non-free/source/sound/festvox-ellpc11k_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/non-free/source/sound/festvox-ellpc11k_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/non-free/source/sound/festlex-oald_1.4.0.orig.tar.gz
http://archive.debian.org/debian/dists/potato/non-free/source/sound/festlex-oald_1.4.0-1.dsc
http://archive.debian.org/debian/dists/potato/non-free/source/sound/festlex-oald_1.4.0-1.diff.gz
http://archive.debian.org/debian/dists/potato/non-free/source/tex/dvi2tty_5.1.orig.tar.gz
http://archive.debian.org/debian/dists/potato/non-free/source/tex/dvi2tty_5.1-13.dsc
http://archive.debian.org/debian/dists/potato/non-free/source/tex/dvi2tty_5.1-13.diff.gz
#!/usr/bin/python

# Copyright (C) 2014 Stefano Zacchiroli
# License: GNU General Public License, version 3 or above

# Check Sources.gz file in a given Debian mirror for referenced, but missing,
# files of a source packages; try to guess the proper symlink target from pool.

from __future__ import print_function

import glob
import os
import sys

from debian import deb822


try:
    target_dir = sys.argv[1]
except IndexError:
    target_dir = os.curdir
dists_dir = os.path.join(target_dir, 'dists')
pool_dir = os.path.join(target_dir, 'pool')
if not os.path.isdir(dists_dir) or not os.path.isdir(pool_dir):
    print("%s doesn't look like a debian mirror; it should contain dists/ and pool/"
          % target_dir)
    sys.exit(1)


def pkg_prefix(pkg):
    if pkg.startswith('lib'):
        assert len(pkg) >= 4
        return pkg[:4]
    else:
        assert pkg
        return pkg[:1]


def guess_target(path, pool_dir):
    # e.g. path="dists/potato/main/source/games/xsol_0.31-3.1.dsc"
    # to be guessed:    "pool/main/x/xsol/xsol_0.31-3.1.dsc"
    steps = path.split('/')
    area = steps[2]	# e.g. "main"
    pkg = steps[-1].split('_')[0]	# e.g. "xsol"

    target = os.path.join(pool_dir, area, pkg_prefix(pkg), pkg, steps[-1])
    if os.path.isfile(target):
        return target
    else:
        return None


os.chdir(target_dir)
for path in glob.glob('dists/*/*/source/Sources.gz'):
    release = path.split('/')[1]
    if os.path.islink('dists/' + release):
        continue	# avoid scanning twice release w/ aliases
    print('scanning %s...' % path, file=sys.stderr)
    with open(path) as index:
        for pkg in deb822.Sources.iter_paragraphs(index):
            src_dir = pkg['directory']
            for file in pkg['files']:
                src_file = os.path.join(src_dir, file['name'])
                if not os.path.isfile(src_file):
                    dest_file = guess_target(src_file, 'pool')
                    if dest_file:
                        _src_file = os.path.abspath(src_file)
                        _dest_file = os.path.abspath(dest_file)
                        ln = 'ln -fs %s %s' % \
                             (os.path.relpath(_dest_file,
                                              os.path.dirname(_src_file)),
                              _src_file)
                    else:
                        dest_file = ''
                        ln = ''
                    print('missing\t%s\t%s\t%s' % (src_file, dest_file, ln))

Reply via email to