forked from victorb/arch-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-gentoo-distfiles.generatelist.sh
51 lines (48 loc) · 1.43 KB
/
sync-gentoo-distfiles.generatelist.sh
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
#!/bin/bash
REPONAME="gentoo-distfiles"
DSTBASE="${HOME}/${REPONAME}"
DST="${DSTBASE}$1"
getipfsfilestat() {
local l=$1
# convert full path, to ipfs repo based path
# /home/user/gentoo-distfiles/ should become gentoo-distfiles/
local fpath=${REPONAME}${l#${DSTBASE}}
if [[ -L "$l" ]]; then
# there are some issues with symlink - it is mostly ok to ignore those issues
local symlinkhash=$(ipfs add --local -q -r -n --raw-leaves --nocopy -H "$l")
local s="symlink:$fpath -> $(readlink -n $l):${symlinkhash}:0"
else
# starting all these processes is horrible, but for now there is no native recursive support
local s=$(ipfs files stat --local --format "<type>:$fpath:<hash>:<cumulsize>" "/$fpath")
fi
local type="${s%:*:*:*}"
case $type in
file)
;;
symlink)
;;
directory)
# directories should have trailing /, but only one
case $fpath in
*/) ;;
*) local s=$s/ ;;
esac
;;
*)
>&2 echo "Unsupported type $s for $l, trying readding"
NEWHASH=$(ipfs add --local -Q -r --nocopy --raw-leaves -H "$l")
ipfs files cp /ipfs/${NEWHASH} "/$fpath"
;;
esac
local namehashsize="${s#*:}"
# output path:hash:size
echo $namehashsize
}
# run N tasks in parallel batches
N=4
# trailing / here is to make sure we get symlink target, not symlink itself
find ${DSTBASE}/ | while read l; do
((i=i%N)); ((i++==0)) && wait
getipfsfilestat "$l" &
done
wait