make_mirror.sh: create temporary directory inside the cache and use hardlinks to avoid unnecessary I/O

pull/1/head
parent 643152ec16
commit 4ffa7bb69b
Signed by: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -50,7 +50,10 @@ fi
for nativearch in $arch1 $arch2; do for nativearch in $arch1 $arch2; do
for dist in stable testing unstable; do for dist in stable testing unstable; do
rootdir=$(mktemp --directory) # use a subdirectory of $newcachedir so that we can use
# hardlinks
rootdir="$newcachedir/apt"
mkdir -p "$rootdir"
for p in /etc/apt/apt.conf.d /etc/apt/sources.list.d /etc/apt/preferences.d /var/cache/apt/archives /var/lib/apt/lists/partial /var/lib/dpkg; do for p in /etc/apt/apt.conf.d /etc/apt/sources.list.d /etc/apt/preferences.d /var/cache/apt/archives /var/lib/apt/lists/partial /var/lib/dpkg; do
mkdir -p "$rootdir/$p" mkdir -p "$rootdir/$p"
@ -99,9 +102,7 @@ END
# distributions might still need this file # distributions might still need this file
# we have to cp and not symlink because apt # we have to cp and not symlink because apt
# doesn't recognize symlinks # doesn't recognize symlinks
# we cannot do a hardlink because the two cp --link "$oldmirrordir/$fname" "$aptname"
# directories might be on different devices
cp -a "$oldmirrordir/$fname" "$aptname"
echo "$aptname" >> "$rootdir/oldaptnames" echo "$aptname" >> "$rootdir/oldaptnames"
done done
fi fi
@ -146,7 +147,16 @@ END
# make sure that we found the right file by checking its hash # make sure that we found the right file by checking its hash
echo "$md5 $aptname" | md5sum --check echo "$md5 $aptname" | md5sum --check
mkdir -p "$newmirrordir/$dir" mkdir -p "$newmirrordir/$dir"
mv "$aptname" "$newmirrordir/$fname" # since we move hardlinks around, the same hardlink might've been
# moved already into the same place by another distribution.
# mv(1) refuses to copy A to B if both are hardlinks of each other.
if [ "$aptname" -ef "$newmirrordir/$fname" ]; then
# both files are already the same so we just need to
# delete the source
rm "$aptname"
else
mv "$aptname" "$newmirrordir/$fname"
fi
echo "$aptname" >> "$rootdir/newaptnames" echo "$aptname" >> "$rootdir/newaptnames"
fi fi
done done

Loading…
Cancel
Save