#!/bin/sh

MNT=/scratch

DEST=${MNT}/ccc/cont000/louveta/BIN/ELSA/CHAINE_V2/MODULE_PYTHON
SRC=${MNT}/ccc/cont008/louveta/BIN/ELSA/CHAINE_V2/MODULE_PYTHON

mkdir -p $DEST $SRC $SRC/TestLong ${SRC}/TestShort

lfs setstripe -c 1 $DEST
lfs setstripe -c 1 $SRC

##### create source files
echo Creating source files
for i in {1..999}; do
	touch ${SRC}/TestLong/symlink_that_will_create_a_long_structure_$i
	touch ${SRC}/TestShort/f$i
done

###### create a large amount of long links
for i in {1..1}; do
	echo "long : Test${i}"
	mkdir ${DEST}/Test${i}
	(cd ${DEST}/Test${i} && \
        	for j in $(seq -w 1 999); do
 			ln -s ${SRC}/TestLong/symlink_that_will_create_a_long_structure_$j ; 
		done)
done

###### remove long links
for i in {1..1} ; do
	rm -rf ${DEST}/Test${i} &
done
wait

###### create a large amount of short links
for i in {1..1}; do
        echo "short : Test${i}"
        mkdir ${DEST}/Test${i}
        (cd ${DEST}/Test${i} && \
                for j in $(seq -w 1 999); do
                        ln -s ${SRC}/TestShort/f$j ;                                 
                done)
done

echo "Umount & run fsck"
