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

KAFKA-3692: Add quotes to variables in kafka-run-class.sh #1364

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions bin/kafka-run-class.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,85 +50,85 @@ fi

# run ./gradlew copyDependantLibs to get all dependant jars in a local dir
shopt -s nullglob
for dir in $base_dir/core/build/dependant-libs-${SCALA_VERSION}*;
for dir in "$base_dir"/core/build/dependant-libs-${SCALA_VERSION}*;
do
if [ -z $CLASSPATH ] ; then
CLASSPATH=$dir/*
if [ -z "$CLASSPATH" ] ; then
CLASSPATH="$dir/*"
else
CLASSPATH=$CLASSPATH:$dir/*
CLASSPATH="$CLASSPATH:$dir/*"
fi
done

for file in $base_dir/examples/build/libs/kafka-examples*.jar;
for file in "$base_dir"/examples/build/libs/kafka-examples*.jar;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done

for file in $base_dir/clients/build/libs/kafka-clients*.jar;
for file in "$base_dir"/clients/build/libs/kafka-clients*.jar;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done

for file in $base_dir/streams/build/libs/kafka-streams*.jar;
for file in "$base_dir"/streams/build/libs/kafka-streams*.jar;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done

for file in $base_dir/streams/examples/build/libs/kafka-streams-examples*.jar;
for file in "$base_dir"/streams/examples/build/libs/kafka-streams-examples*.jar;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done

for file in $base_dir/streams/build/dependant-libs-${SCALA_VERSION}/rocksdb*.jar;
for file in "$base_dir"/streams/build/dependant-libs-${SCALA_VERSION}/rocksdb*.jar;
do
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
done

for file in $base_dir/tools/build/libs/kafka-tools*.jar;
for file in "$base_dir"/tools/build/libs/kafka-tools*.jar;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done

for dir in $base_dir/tools/build/dependant-libs-${SCALA_VERSION}*;
for dir in "$base_dir"/tools/build/dependant-libs-${SCALA_VERSION}*;
do
CLASSPATH=$CLASSPATH:$dir/*
CLASSPATH="$CLASSPATH:$dir/*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 98, we quote $CLASSPATH and $file separately while here we quote both variables together. Is it because of the *?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the two forms are equivalent

done

for cc_pkg in "api" "runtime" "file" "json" "tools"
do
for file in $base_dir/connect/${cc_pkg}/build/libs/connect-${cc_pkg}*.jar;
for file in "$base_dir"/connect/${cc_pkg}/build/libs/connect-${cc_pkg}*.jar;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done
if [ -d "$base_dir/connect/${cc_pkg}/build/dependant-libs" ] ; then
CLASSPATH=$CLASSPATH:$base_dir/connect/${cc_pkg}/build/dependant-libs/*
CLASSPATH="$CLASSPATH:$base_dir/connect/${cc_pkg}/build/dependant-libs/*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that we quote the whole value here but individual components in other places such as in line 112?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @granders can comment as he knows much shell than I do.

Here is what I get from running shellcheck if I only quote CLASSPATH, which is a tool to check issues in shell scripts.
CLASSPATH="$CLASSPATH":$base_dir/connect/${cc_pkg}/build/dependant-libs/*
^-- SC2125: Brace expansions and globs are literal in assignments. Quote it or use an array.

I think as the globs are treated as literals, it seems OK to include in the glob in the quote.

Copy link
Contributor

@granders granders May 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that these forms are equivalent, (and that globs are literal in assignments) so it actually doesn't make a difference.

(On the other hand, I believe the separation is needed for loops (not assignments) to make use of nullglob trickery to make sure nonexistent files aren't added to the classpath)

fi
done

# classpath addition for release
for file in $base_dir/libs/*;
for file in "$base_dir"/libs/*;
do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done

for file in $base_dir/core/build/libs/kafka_${SCALA_BINARY_VERSION}*.jar;
for file in "$base_dir"/core/build/libs/kafka_${SCALA_BINARY_VERSION}*.jar;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't quote SCALA_BINARY_VERSION because the values should not have spaces?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we definitely want to keep the quotes off of * to preserve the nullglob behavior.

It's probably preferable to use something like "${SCALA_BINARY_VERSION}", but a) this variable shouldn't have spaces, and b) I think everyone is currently in the mode of "let's not change anything else unless absolutely necessary to fix a bug"...

do
if should_include_file "$file"; then
CLASSPATH=$CLASSPATH:$file
CLASSPATH="$CLASSPATH":"$file"
fi
done
shopt -u nullglob
Expand Down