]> git.saurik.com Git - cydia.git/blame - Library/move.sh
Factor out -[Database releasePackages] and use from -[Database dealloc].
[cydia.git] / Library / move.sh
CommitLineData
1951a333
JF
1#!/bin/bash
2
3shopt -s extglob nullglob
4
8b743591
JF
5if [[ ${1:0:1} == - ]]; then
6 v=$1
7 shift 1
8else
9 v=
10fi
11
1951a333
JF
12function df_() {
13 free=$(df -B1 "$1")
14 free=${free% *%*}
15 free=${free%%*( )}
16 free=${free##* }
17 echo "${free}"
18}
19
20function mv_() {
21 src=$1
1951a333 22
09a722fb 23 mkdir -p /var/stash
b26eb97d 24 dst=$(mktemp -d /var/stash/"${src##*/}".XXXXXX)
1951a333
JF
25
26 if [[ -e ${src} ]]; then
27 chmod --reference="${src}" "${dst}"
28 chown --reference="${src}" "${dst}"
29
8b743591 30 cp -aT $v "${src}" "${dst}" || {
1951a333
JF
31 rm -rf "${dst}"
32 exit 1
33 }
34
8b743591 35 rm -rf $v "${src}"
1951a333
JF
36 else
37 chmod 775 "${dst}"
38 chown root.admin "${dst}"
39 fi
40
41 ln -s "${dst}" "${src}"
42}
43
44function shift_() {
fa7bb92f 45 dir=${1%/}
1951a333
JF
46
47 if [[ -d ${dir} && ! -h ${dir} ]]; then
9050015e 48 used=$(/usr/libexec/cydia/du -bs "${dir}")
1951a333
JF
49 used=${used%%$'\t'*}
50 free=$(df_ /var)
51
52 if [[ $((used + 524288)) -lt ${free} ]]; then
09a722fb 53 mv_ "${dir}"
1951a333 54 fi
09a722fb 55 elif [[ ! -e ${dir} ]]; then
1951a333 56 rm -f "${dir}"
09a722fb 57 mv_ "${dir}"
1951a333
JF
58 fi
59}
60
61shift_ "$@"