summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-03-01 20:33:15 -0600
committerDan McGee <dan@archlinux.org>2010-03-01 20:33:15 -0600
commit18a74ca61a44a6716f6e3a160cc32efc6cc6cbab (patch)
tree968b01f48fe46e0b878db82193b1173f028dfb72
parentba7968503f18e5a2537d7d87ce2a5caa582f04f7 (diff)
parentffa88b335b2f756925b388ecbd6681bf3aa58579 (diff)
Merge branch 'filelists'
-rwxr-xr-xcron-jobs/create-filelists78
1 files changed, 50 insertions, 28 deletions
diff --git a/cron-jobs/create-filelists b/cron-jobs/create-filelists
index c9d7db9..84867d8 100755
--- a/cron-jobs/create-filelists
+++ b/cron-jobs/create-filelists
@@ -3,59 +3,80 @@
reposdir="/srv/ftp"
targetdir="/srv/ftp"
repos="core extra testing community community-testing"
+lock="/tmp/create-filelists.lock"
. "$(dirname $0)/../db-functions"
. "$(dirname $0)/../config"
-if [ -f "/tmp/createFileList.lock" ]; then
- echo "Error: createFileList allready in progress."
+if [ -f "$lock" ]; then
+ echo "Error: create-filelists already in progress."
exit 1
fi
-touch "/tmp/createFileList.lock" || exit 1
-TMPDIR="$(mktemp -d /tmp/createFileList.XXXXXX)" || exit 1
-CACHEDIR="$(mktemp -d /tmp/createFileList.XXXXXX)" || exit 1
+touch "$lock" || exit 1
+# location where the package DB is extracted so we know what to include
+DBDIR="$(mktemp -d /tmp/create-filelists.dbdir.XXXXXX)" || exit 1
+# location where the old files DB is extracted to save us some work
+CACHEDIR="$(mktemp -d /tmp/create-filelists.cachedir.XXXXXX)" || exit 1
+# location where the new files DB is built up and eventually zipped
+TMPDIR="$(mktemp -d /tmp/create-filelists.tmpdir.XXXXXX)" || exit 1
#adjust the nice level to run at a lower priority
/usr/bin/renice +10 -p $$ > /dev/null
case "${DBEXT}" in
- *.gz) TAR_OPT="z" ;;
- *.bz2) TAR_OPT="j" ;;
- *.xz) TAR_OPT="J" ;;
- *) echo "Unknown compression type for DBEXT=${DBEXT}" && exit 1 ;;
+ *.gz) TAR_OPT="z" ;;
+ *.bz2) TAR_OPT="j" ;;
+ *.xz) TAR_OPT="J" ;;
+ *) echo "Unknown compression type for DBEXT=${DBEXT}" && exit 1 ;;
esac
FILESEXT="${DBEXT//db/files}"
for repo in $repos; do
- REPO_DB_FILE="${repo}$FILESEXT"
+ REPO_DB_FILE="${repo}$DBEXT"
+ FILES_DB_FILE="${repo}$FILESEXT"
for arch in ${ARCHES[@]}; do
+# echo "Running for architecture $arch, repo $repo"
cd "$reposdir"
repodir="${repo}/os/${arch}"
cached="no"
- # extract old file archive
+ # extract package db archive
if [ -f "${targetdir}/${repodir}/${REPO_DB_FILE}" ]; then
+ mkdir -p "${DBDIR}/${repodir}"
+# echo "extracting $REPO_DB_FILE"
+ bsdtar -xf "${targetdir}/${repodir}/${REPO_DB_FILE}" -C "${DBDIR}/${repodir}"
+ else
+ echo "Fail! Does the repo $repo with arch $arch even exist?"
+ continue
+ fi
+
+ # extract old file archive
+ if [ -f "${targetdir}/${repodir}/${FILES_DB_FILE}" ]; then
mkdir -p "${CACHEDIR}/${repodir}"
- bsdtar -xf "${targetdir}/${repodir}/${REPO_DB_FILE}" -C "${CACHEDIR}/${repodir}"
+# echo "extracting $FILES_DB_FILE"
+ bsdtar -xf "${targetdir}/${repodir}/${FILES_DB_FILE}" -C "${CACHEDIR}/${repodir}"
cached="yes"
fi
# create file lists
- for pkg in $repodir/*${PKGEXT}; do
- pkgname="$(getpkgname "$pkg")"
- pkgver="$(getpkgver "$pkg")"
- tmppkgdir="${TMPDIR}/${repodir}/${pkgname}-${pkgver}"
+ for pkg in $(ls ${DBDIR}/${repodir}); do
+ dbpkgdir="${DBDIR}/${repodir}/${pkg}"
+ cachepkgdir="${CACHEDIR}/${repodir}/${pkg}"
+ tmppkgdir="${TMPDIR}/${repodir}/${pkg}"
mkdir -p "$tmppkgdir"
- if [ -f "${CACHEDIR}/${repodir}/${pkgname}-${pkgver}/files" ]; then
-# echo "cache: $pkgname"
- mv "${CACHEDIR}/${repodir}/${pkgname}-${pkgver}/files" "${tmppkgdir}/files"
+ ln "${dbpkgdir}/desc" "${tmppkgdir}/desc"
+ ln "${dbpkgdir}/depends" "${tmppkgdir}/depends"
+ if [ -f "${cachepkgdir}/files" ]; then
+# echo "cache: $pkg"
+ ln "${cachepkgdir}/files" "${tmppkgdir}/files"
else
-# echo "$repo/$arch: $pkgname"
+# echo "not cache: $repo/$arch: $pkg"
+ filename=$(grep -A1 '^%FILENAME%$' "${dbpkgdir}/desc" | tail -n1)
echo '%FILES%' > "${tmppkgdir}/files"
- bsdtar --exclude=.* -tf "$pkg" >> "${tmppkgdir}/files"
+ bsdtar --exclude=.* -tf "$repodir/$filename" >> "${tmppkgdir}/files"
cached="no"
fi
done
@@ -63,19 +84,20 @@ for repo in $repos; do
# create new file archive
if [ "$cached" == "no" ]; then
# at least one package has changed, so let's rebuild the archive
-# echo "creating ${REPO_DB_FILE}/${arch}"
+# echo "creating ${FILES_DB_FILE}/${arch}"
pkgdir="${targetdir}/${repodir}"
mkdir -p "$pkgdir"
cd "${TMPDIR}/${repodir}"
- [ -f "${pkgdir}/${REPO_DB_FILE}.old" ] && rm "${pkgdir}/${REPO_DB_FILE}.old"
- [ -f "${pkgdir}/${REPO_DB_FILE}" ] && mv "${pkgdir}/${REPO_DB_FILE}" "${pkgdir}/${REPO_DB_FILE}.old"
- bsdtar --exclude=*${DBEXT//\.db/} -c${TAR_OPT}f "${pkgdir}/${REPO_DB_FILE}" *
+ [ -f "${pkgdir}/${FILES_DB_FILE}.old" ] && rm "${pkgdir}/${FILES_DB_FILE}.old"
+ [ -f "${pkgdir}/${FILES_DB_FILE}" ] && mv "${pkgdir}/${FILES_DB_FILE}" "${pkgdir}/${FILES_DB_FILE}.old"
+ bsdtar --exclude=*${DBEXT//\.db/} -c${TAR_OPT}f "${pkgdir}/${FILES_DB_FILE}" *
fi
done
done
cd - >/dev/null
-rm -rf "$TMPDIR" || exit 1
-rm -rf "$CACHEDIR" || exit 1
-rm -f "/tmp/createFileList.lock" || exit 1
+rm -rf "$TMPDIR" "$CACHEDIR" "$DBDIR"
+rm -f "$lock" || exit 1
# echo 'done'
+
+# vim: set ts=4 sw=4 et ft=sh: