#!/bin/bash

# scripts check if changes file exist in repo
# we can't use find on gluster, so teamcity try to
# check this method

# exit codes:
#         0 - file exist
#         1 - file does not exit

REPO=$1
CH_FILE=$2

if [ "x$REPO" == "x" -o "x$CH_FILE" == "x" ]; then
    exit 30
fi

for i in `ls -ld /repo/$REPO/* | grep '^d'| awk '{ print $NF }'`; do
    if [ -f $i/$CH_FILE ]; then
        FLAG="YES"
        break
    fi
done

if [ "x$FLAG" == "xYES" ]; then
    exit 0
else
    exit 1
fi
