summaryrefslogtreecommitdiff
path: root/Tools/portbuild/scripts/dodistfiles
blob: 2db265200b02c8696c1fcd26c739c8a29f773beb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
#
# Process a distfiles/ directory, efficiently moving files from
# .pbtmp/<package>/* into . (relative to distfiles/)
#
# We do this in several stages
#
# 1. Remove incomplete downloads where .pbtmp/<package>/.done does not
#    exist (this is an incomplete transfer and may be corrupted)
#
# 2. Populate the directory hierarchy from .pbtmp/*/ into .
#
# 3. For each subdirectory under .pbtmp/*/, group them together by
#    subdirectory name and move all of the files at once.
#    e.g. .pbtmp/foo-1.0/dir/* and .pbtmp/bar-2.0/dir/* are
#    processed at the same time (contents moved to ./dir/).
#
# 4. Once we have handled the subdirectories, everything left
#    is a plain file in .pbtmp/*/ so we move those in bulk together
#    into .
#
# 5. Clean up

if [ $# != 2 ]; then
  echo "usage: $0 <arch> <branch>"
  exit 1
fi

arch=$1
branch=$2

distdir=/var/portbuild/${arch}/${branch}/distfiles

cd ${distdir} || exit 1

echo "Removing incomplete downloads"

find ${distdir}/.pbtmp/ -name .done -depth 2 | sed -e 's,/.done$,/,' | sort > .done || exit 1
find -d ${distdir}/.pbtmp/ -type d -mindepth 1 |sed -E -e 's,([^/])$,\1/,' > .alldirs || exit 1

sed -E -e "s,^(${distdir}/.pbtmp/[^/]+/).*,\1," < .alldirs | sort -u > .pkgdirs

comm -1 -3 .done .pkgdirs | xargs rm -rf

# Full path of subdirectories under package dirs
grep -E "^${distdir}/.pbtmp/[^/]+/.+/" .alldirs > .pkgsubdirs

# All subdirectories under package dirs
sed -E -e "s,^${distdir}/.pbtmp/[^/]+/,," < .pkgsubdirs | grep -v '^$' | sort -u > .subdirs

echo "Making directories"
cat .subdirs | xargs mkdir -p

# Move files in each subdir
for i in `cat .pkgsubdirs`; do
  find ${i} -type f -depth 1 \! -name .done | xargs -J % mv % ${distdir}/${i#${distdir}/.pbtmp/*/}
#  rmdir ${i} || exit 1
#  rm -rf ${distdir}/.pbtmp/$i
done
cat .pkgsubdirs | xargs rmdir || exit 1

echo "Moving remaining distfiles"
find ${distdir}/.pbtmp/ -type f -depth 2 \! -name .done | xargs -J % mv % ${distdir}

echo "Cleaning up"
sed -e 's,$,.done,' < .pkgdirs | xargs rm -f || exit 1
cat .pkgdirs | xargs rmdir || exit 1
rmdir .pbtmp || exit 1

rm -f .alldirs .done .pkgdirs .pkgsubdirs .subdirs || exit 1