Skip to content

Commit d9dda53

Browse files
authored
GUACAMOLE-2132: Merge fix license generation to support whitespace in filenames.
2 parents 8168baa + c5caac8 commit d9dda53

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

doc/licenses/clean-license-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ LICENSES_DIR="`dirname "$0"`"
4545
find "$LICENSES_DIR" -type f \
4646
| xargs grep -l '^# --- BEGIN LICENSE FILE \(\[[^]]*\] \)\?---$' \
4747
| xargs grep -l '^#[[:space:]]*Source:' \
48-
| while read FILENAME; do
48+
| while IFS='' read -r FILENAME; do
4949

5050
sed -i -n \
5151
-e '/^# --- BEGIN LICENSE FILE \(\[[^]]*\] \)\?---$/q' \

doc/licenses/generate-license-files.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ DEPENDENCY_LIST="$1"
176176
##
177177
OUTPUT_DIR="$2"
178178

179+
##
180+
## A single tab characer, as may be needed to split input lines by tabs using
181+
## the "read" command and "IFS" environment variable.
182+
##
183+
TAB_CHAR="`printf '\t'`"
184+
179185
##
180186
## Lists the license information directories (subdirectories of the
181187
## "doc/licenses/" directory in the main guacamole-client source tree) that
@@ -191,19 +197,19 @@ list_dependency_license_info() {
191197

192198
# List the license directories of all runtime dependencies, as dictated by
193199
# the "dep-coordinates.txt" files included within those directories
194-
sed 's/^[[:space:]]\+//' | grep -o '^[^: ]\+\(:[^: ]*\)\{1,3\}' \
195-
| while read DEPENDENCY; do
200+
sed 's/^[[:space:]]\+//' | grep -o '^[^:[:space:]]\+\(:[^:[:space:]]*\)\{1,3\}' \
201+
| while IFS='' read -r DEPENDENCY; do
196202

197203
local DEPENDENCY_REGEX="`echo "$DEPENDENCY" | sed 's/[^:]*/\\\\(&\\\\|\*\\\\)/g'`"
198204
local VERSION="`echo "$DEPENDENCY" | sed 's/.*://'`"
199205

200206
if ! grep -l "^$DEPENDENCY_REGEX[[:space:]]*$" "$LICENSES_DIR"/*/dep-coordinates.txt \
201-
| sed "s/$/ $VERSION/g"; then
207+
| sed "s/$/\\t$VERSION/g"; then
202208
error "License information missing for $DEPENDENCY"
203209
fi
204210

205-
done | sort -u -k 1,1 | while read LICENSE_INFO_COORDS_FILE VERSION; do
206-
printf '%s %s\n' "`dirname "$LICENSE_INFO_COORDS_FILE"`" "$VERSION"
211+
done | sort -u -t "$TAB_CHAR" -k 1,1 | while IFS="$TAB_CHAR" read -r LICENSE_INFO_COORDS_FILE VERSION; do
212+
printf '%s\t%s\n' "`dirname "$LICENSE_INFO_COORDS_FILE"`" "$VERSION"
207213
done
208214

209215
# Include license directories for all dependencies not pulled in automatically
@@ -220,7 +226,7 @@ list_dependency_license_info() {
220226
## written to STDOUT. Each directory must be on its own line.
221227
##
222228
sort_dependency_license_info() {
223-
while read LICENSE_INFO VERSION; do
229+
while IFS="$TAB_CHAR" read -r LICENSE_INFO VERSION; do
224230

225231
local PRIMARY_FILE="`primary_file "$LICENSE_INFO"`"
226232

@@ -229,9 +235,9 @@ sort_dependency_license_info() {
229235
[ -n "$PRIMARY_FILE" ] || continue
230236

231237
local NAME="`get_header_value "$PRIMARY_FILE" Name`"
232-
printf "%s\t%s %s\n" "$NAME" "$LICENSE_INFO" "$VERSION"
238+
printf '%s\t%s\t%s\n' "$NAME" "$LICENSE_INFO" "$VERSION"
233239

234-
done | sort -f | cut -f2
240+
done | sort -f | cut -f2-
235241
}
236242

237243
##
@@ -265,7 +271,7 @@ error() {
265271
## non-zero (failure) otherwise.
266272
##
267273
single_result() {
268-
read RESULT && echo "$RESULT"
274+
IFS='' read -r RESULT && echo "$RESULT"
269275
! read DUMMY
270276
}
271277

@@ -357,13 +363,13 @@ format_multiline() {
357363
local INDENT=" "
358364
local NEXT_LINE
359365

360-
read FIRST_LINE
366+
IFS='' read -r FIRST_LINE
361367

362-
if read NEXT_LINE; then
368+
if IFS='' read -r NEXT_LINE; then
363369
printf '\n'
364370
printf "%s%s\n" "$INDENT" "$FIRST_LINE"
365371
printf "%s%s\n" "$INDENT" "$NEXT_LINE"
366-
while read NEXT_LINE; do
372+
while IFS='' read -r NEXT_LINE; do
367373
printf "%s%s\n" "$INDENT" "$NEXT_LINE"
368374
done
369375
else
@@ -495,7 +501,7 @@ append_license() {
495501

496502
get_header_value "$FILENAME" Source \
497503
| subst_version "$VERSION" \
498-
| while read -r LICENSE_URL; do
504+
| while IFS='' read -r LICENSE_URL; do
499505

500506
local LICENSE="`curl -SsfL "$LICENSE_URL" | sed 's:\r$::g'`"
501507
if [ -n "$LICENSE" ]; then
@@ -546,7 +552,7 @@ cp "$BASEDIR/NOTICE" "$OUTPUT_DIR/"
546552
PREAMBLE_ADDED=0
547553
find "$DEPENDENCY_LIST" -type f -exec cat '{}' + | \
548554
list_dependency_license_info | sort_dependency_license_info | \
549-
while read LICENSE_INFO_DIR VERSION; do
555+
while IFS="$TAB_CHAR" read -r LICENSE_INFO_DIR VERSION; do
550556

551557
# Add subcomponent license preamble if not already added
552558
if [ "$PREAMBLE_ADDED" = 0 ]; then
@@ -564,8 +570,8 @@ EOF
564570
fi
565571

566572
# Refresh any outstanding licenses from defined download link
567-
find "$LICENSE_INFO_DIR" -type f | xargs grep -l '^#[[:space:]]*Source:' \
568-
| while read FILENAME; do
573+
find "$LICENSE_INFO_DIR" -type f -print0 | xargs -0 grep -l '^#[[:space:]]*Source:' \
574+
| while IFS='' read -r FILENAME; do
569575
if [ -z "`get_license "$FILENAME" "$VERSION"`" ]; then
570576
if [ "$DOWNLOAD_MISSING_LICENSES" = "true" ]; then
571577
info "Downloading updated `basename "$FILENAME"` for `basename "$LICENSE_INFO_DIR"` ($VERSION)..."

0 commit comments

Comments
 (0)