X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/1951a3330b4984fac38d8f52129ab6bf31aadc7d..7afcea1c7f36f0c4ee9c4d4b53618df39073d851:/Library/move.sh diff --git a/Library/move.sh b/Library/move.sh index 31c89e4c..abfe2edf 100755 --- a/Library/move.sh +++ b/Library/move.sh @@ -2,6 +2,13 @@ shopt -s extglob nullglob +if [[ ${1:0:1} == - ]]; then + v=$1 + shift 1 +else + v= +fi + function df_() { free=$(df -B1 "$1") free=${free% *%*} @@ -12,24 +19,20 @@ function df_() { function mv_() { src=$1 - dst=$2 - if [[ -e ${dst} ]]; then - dst=$(mktemp -d /var/cydia.XXXXXX) - else - mkdir -p "${dst}" - fi + mkdir -p /var/stash + dst=$(mktemp -d /var/stash/"${src##*/}".XXXXXX) if [[ -e ${src} ]]; then chmod --reference="${src}" "${dst}" chown --reference="${src}" "${dst}" - cp -aT "${src}" "${dst}" || { + cp -aT $v "${src}" "${dst}" || { rm -rf "${dst}" exit 1 } - rm -rf "${src}" + rm -rf $v "${src}" else chmod 775 "${dst}" chown root.admin "${dst}" @@ -39,8 +42,7 @@ function mv_() { } function shift_() { - dir=$1 - dst=$2 + dir=${1%/} if [[ -d ${dir} && ! -h ${dir} ]]; then used=$(du -bs "${dir}") @@ -48,11 +50,11 @@ function shift_() { free=$(df_ /var) if [[ $((used + 524288)) -lt ${free} ]]; then - mv_ "${dir}" "${dst}" + mv_ "${dir}" fi - elif [[ -h ${dir} && ! -e ${dir} ]]; then + elif [[ ! -e ${dir} ]]; then rm -f "${dir}" - mv_ "${dir}" "${dst}" + mv_ "${dir}" fi }