diff --git a/masync b/masync index f1a1fa9..44dd465 100755 --- a/masync +++ b/masync @@ -87,12 +87,25 @@ feeddeletes() { echo "grep $1 ${SYNCFILE}" grep $1 ${SYNCFILE} | while read hash pid when status localpath remotepath; do remoterelativepath=$(echo "$remotepath" | cut -d : -f 2) + remotehost=$(echo "$remotepath" | cut -d : -f 1 | cut -d @ -f 2) + remotefiles=$(mktemp) + ## request list of remote files to remotehost + ssh ${remotehost} find "'${remoterelativepath}'" > ${remotefiles} + ## read my snapshot while read path; do - if [ ! -e "${path}" ]; then - echo "${path} not exists" - echo ${path} | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes} + if [[ -e "${path}" ]]; then + tocheckremotepath=$(echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g") + if ! grep -Fxq "${tocheckremotepath}" ${remotefiles}; then + echo "${tocheckremotepath} not exists in remote remove ${path} in local"; + rm -rf "${path}" + fi + else + echo "${path} Noexits"; + ## if controlled file doesn't exist in local delete it on remote + echo "${path}" | sed -e "s~${localpath}~${remoterelativepath}~g" | tee -a ${queuedeletes} fi done < ${snapfile} + rm -rf ${remotefiles} done }