#!/bin/bash
cvmfs_test_name="Creating Symlinks in Directory"
cvmfs_test_autofs_on_startup=false
cvmfs_test_suites="quick"

produce_files_in() {
	local working_dir=$1

	pushdir $working_dir

  mkdir dir4
  echo "meaningless content" > dir4/meaningless_file
  ln -s meaningless_file dir4/symlink_to_meaningless_file

  mkdir dir5
  echo "meaningless content" > dir5/meaninglessFile
  ln -s meaninglessFile dir5/symlinkToMeaninglessFile

	popdir
}

cvmfs_run_test() {
  logfile=$1
  local repo_dir=/cvmfs/$CVMFS_TEST_REPO

  local scratch_dir=$(pwd)
  mkdir reference_dir
  local reference_dir=$scratch_dir/reference_dir

  echo "create a fresh repository named $CVMFS_TEST_REPO with user $CVMFS_TEST_USER"
  create_empty_repo $CVMFS_TEST_REPO $CVMFS_TEST_USER || return $?

  echo "starting transaction to edit repository"
  start_transaction $CVMFS_TEST_REPO || return $?

  echo "putting some stuff in the new repository"
  produce_files_in $repo_dir || return 3

  echo "putting exactly the same stuff in the scratch space for comparison"
  produce_files_in $reference_dir || return 4

  echo "creating CVMFS snapshot"
  publish_repo $CVMFS_TEST_REPO || return $?

  echo "compare the results of cvmfs to our reference copy"
  compare_directories $repo_dir $reference_dir || return $?

  echo "check catalog and data integrity"
  check_repository $CVMFS_TEST_REPO -i || return $?

  return 0
}

