@@ -11,8 +11,10 @@ SERVICE_DIR="databricks-sdk-java/src/main/java/com/databricks/sdk/service"
1111# Files/directories to exclude from deletion (relative to service directory)
1212# Add specific files or directories that should be preserved during cleanup
1313EXCLUDES=(
14- " iam/*"
15- " sharing/*"
14+ " iam"
15+ " sharing/SharesExtService.java"
16+ " sharing/SharesExtImpl.java"
17+ " sharing/SharesExtAPI.java"
1618)
1719
1820echo " 🧹 Cleaning service directory: $SERVICE_DIR "
2830should_exclude () {
2931 local item=" $1 "
3032 local relative_path=" ${item# $SERVICE_DIR / } "
33+ # Remove trailing slash if present
34+ relative_path=" ${relative_path%/ } "
3135
3236 for exclude_pattern in " ${EXCLUDES[@]} " ; do
33- if [[ -n " $exclude_pattern " && " $relative_path " == $exclude_pattern ]]; then
34- return 0 # Should exclude
37+ if [[ -n " $exclude_pattern " ]]; then
38+ # Handle directory exclusions (exact match)
39+ if [[ " $relative_path " == " $exclude_pattern " ]]; then
40+ return 0 # Should exclude
41+ fi
42+ # Handle file exclusions (check if this item contains the excluded file)
43+ if [[ " $exclude_pattern " == * " /" * ]]; then
44+ local exclude_dir=" ${exclude_pattern%%/* } "
45+ if [[ " $relative_path " == " $exclude_dir " ]]; then
46+ # This is a directory that contains excluded files, handle specially
47+ return 2 # Special case: partial exclusion
48+ fi
49+ fi
3550 fi
3651 done
3752 return 1 # Should not exclude
3853}
3954
55+ # Function to selectively clean a directory with file-level exclusions
56+ selective_clean_directory () {
57+ local dir=" $1 "
58+ local dir_name=" ${dir# $SERVICE_DIR / } "
59+ dir_name=" ${dir_name%/ } "
60+
61+ echo " 🔍 Selectively cleaning directory: $dir_name "
62+
63+ # Find all files in this directory
64+ while IFS= read -r -d ' ' file; do
65+ local file_relative=" ${file# $SERVICE_DIR / } "
66+ local should_keep=false
67+
68+ # Check if this file should be excluded
69+ for exclude_pattern in " ${EXCLUDES[@]} " ; do
70+ if [[ " $file_relative " == " $exclude_pattern " ]]; then
71+ should_keep=true
72+ break
73+ fi
74+ done
75+
76+ if $should_keep ; then
77+ echo " ⏭️ Keeping: $file_relative "
78+ else
79+ echo " 🗑️ Deleting: $file_relative "
80+ rm -f " $file "
81+ fi
82+ done < <( find " $dir " -type f -print0)
83+
84+ # Remove empty subdirectories
85+ find " $dir " -type d -empty -delete 2> /dev/null || true
86+ }
87+
4088# Find all items in the service directory (1 level deep)
4189while IFS= read -r -d ' ' item; do
42- if should_exclude " $item " ; then
43- echo " ⏭️ Skipping: ${item# $SERVICE_DIR / } "
44- else
45- echo " 🗑️ Deleting: ${item# $SERVICE_DIR / } "
46- rm -rf " $item "
47- fi
48- done < <( find " $SERVICE_DIR " -mindepth 1 -maxdepth 1 -print0)
90+ exclusion_result=$( should_exclude " $item " ; echo $? )
91+
92+ case $exclusion_result in
93+ 0) # Full exclusion
94+ echo " ⏭️ Skipping: ${item# $SERVICE_DIR / } "
95+ ;;
96+ 2) # Partial exclusion (directory with some excluded files)
97+ selective_clean_directory " $item "
98+ ;;
99+ * ) # No exclusion - delete entirely
100+ echo " 🗑️ Deleting: ${item# $SERVICE_DIR / } "
101+ rm -rf " $item "
102+ ;;
103+ esac
104+ done < <( find " $SERVICE_DIR " -mindepth 1 -maxdepth 1 -type d -print0)
49105
50106echo " ✅ Service directory cleanup completed"
0 commit comments