Don't ever try to overwrite /usr/bin/git

Previously, version.sh got the path to git as its first and only argument. Since
the previous commit, this is not the path to src/version.cpp and the second
argument is the path to git.

However, let's assume someone does "git pull && make". They still have the old
Makefile laying around, which will pass the path to git as the first argument to
version.sh. Thus, this will overwrite /usr/bin/git with some generated source
code. Whoops.

Thanks to KindOne for reporting this problem!

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2013-03-31 20:35:05 +02:00
parent 58a34fa5ad
commit 3a7dc7aa73
2 changed files with 7 additions and 10 deletions

View File

@@ -103,10 +103,10 @@ src/%.o: src/%.cpp Makefile
# If git-describe differs from .version_extra, add a phony target to dependencies, forcing version.o to be recompiled
# znc-0.200-430-g80acaa7 -> -DVERSION_EXTRA="\"-git-430-80acaa7\""
src/version.cpp: Makefile version.sh $(shell if [ x`cat .version_extra 2> /dev/null` != x`$(srcdir)/version.sh '' $(GIT) 2> /dev/null` ]; then echo version_extra_recompile; fi)
src/version.cpp: Makefile version.sh $(shell if [ x`cat .version_extra 2> /dev/null` != x`$(srcdir)/version.sh $(GIT) 2> /dev/null` ]; then echo version_extra_recompile; fi)
@mkdir -p .depend src
$(E) Building source file version.cpp...
$(Q)$(srcdir)/version.sh "$@" "$(GIT)" > .version_extra 2> /dev/null
$(Q)WRITE_OUTPUT=yes $(srcdir)/version.sh "$(GIT)" > .version_extra 2> /dev/null
install: znc $(LIBZNC)
test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir)

View File

@@ -3,11 +3,8 @@
# Get the path to the source directory
GIT_DIR=`dirname $0`
# Our first argument should be the file that we write to
OUTPUT="$1"
# Our second argument should be the path to git
GIT="$2"
# Our argument should be the path to git
GIT="$1"
if [ "x$GIT" = "x" ]
then
EXTRA=""
@@ -30,10 +27,10 @@ else
fi
# Generate output file, if any
if [ "x$OUTPUT" != "x" ]
if [ "x$WRITE_OUTPUT" = "xyes" ]
then
echo '#include <znc/version.h>' > $OUTPUT
echo "const char* ZNC_VERSION_EXTRA = \"$EXTRA\";" >> $OUTPUT
echo '#include <znc/version.h>' > src/version.cpp
echo "const char* ZNC_VERSION_EXTRA = \"$EXTRA\";" >> src/version.cpp
fi
echo "$EXTRA"