From 114de6fb2690a4aabfae9fed4dde1eff8089ebb8 Mon Sep 17 00:00:00 2001 From: Alvaro Tolosa Delgado <114166109+atolosadelgado@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:21:51 +0200 Subject: [PATCH] script that compares all the files named the same within a given path (#294) --- test/CMakeLists.txt | 10 ++++++ utils/IdenticalFiles_ToBeIgnored.txt | 35 ++++++++++++++++++++ utils/compareIdenticalFiles.sh | 49 ++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 utils/IdenticalFiles_ToBeIgnored.txt create mode 100755 utils/compareIdenticalFiles.sh diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3d4876777..8817a1991 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -149,3 +149,13 @@ ADD_TEST( t_SensThickness_Clic_o2_v4 "${CMAKE_INSTALL_PREFIX}/bin/run_test_${Pac ${CMAKE_INSTALL_PREFIX}/bin/TestSensThickness ${CMAKE_CURRENT_SOURCE_DIR}/../CLIC/compact/CLIC_o2_v04/CLIC_o2_v04.xml 300 50 ) ADD_TEST( t_SensThickness_CLIC_o3_v15 "${CMAKE_INSTALL_PREFIX}/bin/run_test_${PackageName}.sh" ${CMAKE_INSTALL_PREFIX}/bin/TestSensThickness ${CMAKE_CURRENT_SOURCE_DIR}/../CLIC/compact/CLIC_o3_v15/CLIC_o3_v15.xml 100 50 ) + +#-------------------------------------------------- +# check if files named the same contain the same in FCCee +ADD_TEST( + NAME t_test_files_versions_FCCee + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_${PackageName}.sh" + "${PROJECT_SOURCE_DIR}/utils/compareIdenticalFiles.sh" + "${PROJECT_SOURCE_DIR}/FCCee" + "${PROJECT_SOURCE_DIR}/utils/IdenticalFiles_ToBeIgnored.txt" +) diff --git a/utils/IdenticalFiles_ToBeIgnored.txt b/utils/IdenticalFiles_ToBeIgnored.txt new file mode 100644 index 000000000..9e760a722 --- /dev/null +++ b/utils/IdenticalFiles_ToBeIgnored.txt @@ -0,0 +1,35 @@ +README.md +CMakeLists.txt +DectDimensions.xml +materials.xml +#__CLD_ill_named_files__ +additional_materials.xml +BeamInstrumentation_o3_v01_overlap.xml +BeamInstrumentation_o3_v02_fitShield.xml +Beampipe_o4_v03_noNotch_Ta_cone.xml +Beampipe_o4_v04_noNotch_W_n02_smallBP.xml +Beampipe_o4_v04_noNotch_W_n02.xml +Beampipe_o4_v05.xml +ECalBarrel_o2_v01_03.xml +ECalEndcap_o2_v01_03.xml +elements.xml +FCCee_DectDimensions.xml +FCCee_o2_v02.xml +HCalBarrel_o1_v01_01.xml +HCalEndcap_o1_v01_01.xml +HOMAbsorber_v00.xml +InnerTracker_o2_v06_02.xml +LumiCal_o3_v02_02.xml +LumiCal_o3_v02_03.xml +OuterTracker_o2_v06_02.xml +Solenoid_o1_v01_02.xml +Vertex_o4_v05_smallBP.xml +Vertex_o4_v05.xml +YokeBarrel_o1_v01_02.xml +YokeEndcap_o1_v01_02.xml +#__ALLEGRO_ill_named_files__ +ECalBarrel_thetamodulemerged.xml +ECalBarrel_thetamodulemerged_calibration.xml +ECalBarrel_thetamodulemerged_upstream.xml +#__FCCee_ill_named_files__ +FCCee_DectEmptyMaster.xml diff --git a/utils/compareIdenticalFiles.sh b/utils/compareIdenticalFiles.sh new file mode 100755 index 000000000..e22c658c0 --- /dev/null +++ b/utils/compareIdenticalFiles.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# This script compares all the files named the same within a given path (as argument) +# If files with the same name have different contents, it prints the paths of those files +# If the files are identical, nothing is printed +# Files listed in an ignore file are excluded + +# Usage: ./script.sh + +search_dir="$1" +ignore_file="$2" + +# Read filenames to ignore from the ignore file +files_to_ignore=$(<"$ignore_file") + +# Create an associative array to store file paths with the same names +declare -A file_names + +# Initialize status code variable +status_code=0 + +# Iterate through files in the directory +while IFS= read -r -d '' file; do + # Get the base name of the file (without the path) + file_name=$(basename "$file") + + # Ignore files listed in the ignore file + if grep -qx "$file_name" <<< "$files_to_ignore"; then + continue + fi + + # Check if there is already a file with the same name + if [[ -n "${file_names[$file_name]}" ]]; then + # Compare the contents of the files + if ! cmp -s "$file" "${file_names[$file_name]}"; then + # Print the paths of the files if they differ + echo "Error. Files with the same name but different contents:" + echo "$file" + echo "${file_names[$file_name]}" + echo + status_code=1 + fi + else + # Store the file path in the array + file_names["$file_name"]="$file" + fi +done < <(find "$search_dir" -not -path '*/.*' -type f -print0) + +exit $status_code