Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script that compares all the files named the same within a given path #294

Merged
merged 10 commits into from
Aug 2, 2024
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ 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
SET( test_name "test_files_versions_FCCee" )
ADD_TEST(
NAME t_${test_name}
jmcarcell marked this conversation as resolved.
Show resolved Hide resolved
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"
)
35 changes: 35 additions & 0 deletions utils/IdenticalFiles_ToBeIgnored.txt
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions utils/compareIdenticalFiles.sh
Original file line number Diff line number Diff line change
@@ -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> <ignore_file>

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
Loading