Skip to content

Commit 02125e3

Browse files
authored
fix(scripts): streamline temporary file handling in checksum-sort.sh (#646)
- Updated temporary file naming conventions for consistency. - Removed unnecessary whitespace around file redirection in multiple functions. - Ensured proper formatting and adherence to coding standards throughout the script.
1 parent 9a0a13a commit 02125e3

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

scripts/checksum-sort.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ get_timestamp() {
6969
# Update date and version headers, and add checksum after Title
7070
update_headers() {
7171
local file="$1"
72-
local temp_file="${file}.tmp.$$"
72+
local temp_file="$file.tmp.$$"
7373
local datetime version checksum
7474

7575
datetime=$(get_timestamp "datetime")
@@ -95,12 +95,12 @@ update_headers() {
9595
else
9696
echo "$line"
9797
fi
98-
done < "$file" > "$temp_file"
98+
done <"$file" >"$temp_file"
9999

100100
# If Last modified or Version headers weren't found, add them after Title/Checksum
101101
if [[ "$found_last_modified" == "false" ]] || [[ "$found_version" == "false" ]]; then
102-
local temp_file2="${file}.tmp2.$$"
103-
102+
local temp_file2="$file.tmp2.$$"
103+
104104
while IFS= read -r line || [[ -n "$line" ]]; do
105105
echo "$line"
106106
# After Title line, add Checksum (placeholder), then missing headers
@@ -113,8 +113,8 @@ update_headers() {
113113
echo "! Version: $version"
114114
fi
115115
fi
116-
done < "$temp_file" > "$temp_file2"
117-
116+
done <"$temp_file" >"$temp_file2"
117+
118118
mv "$temp_file2" "$temp_file"
119119
fi
120120

@@ -128,7 +128,7 @@ add_checksum() {
128128

129129
# Calculate checksum after updating headers
130130
checksum=$(calculate_checksum "$file")
131-
temp_file="${file}.tmp.$$"
131+
temp_file="$file.tmp.$$"
132132

133133
# Find Title line and insert Checksum right after it
134134
local title_found=false
@@ -139,23 +139,23 @@ add_checksum() {
139139
echo "! Checksum: $checksum"
140140
title_found=true
141141
fi
142-
done < "$file" > "$temp_file"
142+
done <"$file" >"$temp_file"
143143

144144
# If no Title line was found, prepend checksum
145145
if [[ "$title_found" == "false" ]]; then
146-
echo "! Checksum: $checksum" > "$temp_file"
147-
cat "$file" >> "$temp_file"
146+
echo "! Checksum: $checksum" >"$temp_file"
147+
cat "$file" >>"$temp_file"
148148
fi
149149

150150
mv "$temp_file" "$file"
151-
151+
152152
log_info "📝 Checksum: $checksum"
153153
}
154154

155155
# Sort the filter file (sort filter rules while preserving header)
156156
sort_filter() {
157157
local file="$1"
158-
local temp_file="${file}.tmp.$$"
158+
local temp_file="$file.tmp.$$"
159159
local header_end=0
160160
local line_num=0
161161

@@ -166,18 +166,18 @@ sort_filter() {
166166
header_end=$line_num
167167
break
168168
fi
169-
done < "$file"
169+
done <"$file"
170170

171171
if [[ $header_end -eq 0 ]]; then
172172
# No filter rules, just return
173173
return
174174
fi
175175

176176
# Extract header (lines before first filter rule)
177-
head -n $((header_end - 1)) "$file" > "$temp_file"
177+
head -n $((header_end - 1)) "$file" >"$temp_file"
178178

179179
# Sort and append filter rules (skip empty lines at start of content)
180-
tail -n +"$header_end" "$file" | sort -u >> "$temp_file"
180+
tail -n +"$header_end" "$file" | sort -u >>"$temp_file"
181181

182182
mv "$temp_file" "$file"
183183
}
@@ -256,4 +256,4 @@ main() {
256256
}
257257

258258
# Run main function with all arguments
259-
main "$@"
259+
main "$@"

0 commit comments

Comments
 (0)