#!/bin/bash
# Checks an issue with -O2 and -fno-strict-aliasing, reflected on dpns-getacl answer from server
# when ACL field is empty
# meta: proxy=true
# meta: preconfig=../../DPM-config

SCRIPTDIR="$(dirname "$(readlink -f ${BASH_SOURCE})")"
source "${SCRIPTDIR}/../../Macros"

err=""
TEST_FOLDER="/dpm/cern.ch/home/$VO/dpm-bug-no-strict-aliasing"

# Create the folder
echo "Creating test folder"
RUN_COMMAND "dpns-mkdir \"${TEST_FOLDER}\""
if [ $? -ne 0 ]; then
  err="Could not create the test folder"
else
  # Remove defaults
  echo "Removing defaults"

  RUN_COMMAND "dpns-setacl -d \"d:u::,d:g::,d:o::\" \"${TEST_FOLDER}\""
  if [ $? -ne 0 ]; then
    err="Could not remove default ACLS"
  else
    RUN_COMMAND "dpns-getacl \"${TEST_FOLDER}\""
    if [ $? -ne 0 ]; then
      err="Could not recover the ACLs"
    else
      echo "${ERROR}" | grep "No such uid" &> /dev/null
      if [ $? -eq 0 ]; then
        err="Bug reproduced!!"
      fi
    fi
  fi

  # Remove
  RUN_COMMAND "dpns-rm -r \"${TEST_FOLDER}\""
  if [ $? -ne 0 ]; then
    err="Could not remove the test folder"
  fi
fi


if [ "$err" == "" ]; then
  TEST_PASSED
else
  TEST_FAILED "$err"
fi

