Skip to contentSkip to conversation

pkg-download: make sure git downloads fail for unknown versions

PATCH New Thomas Petazzoni 2 participants 2 messages Feb 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pkg-download: make sure git downloads fail for unknown versions

The current git download helper creates the tarball by doing:

git archive <version> | gzip -c > <tarball>

Unfortunately, even if "git archive" fails and returns a non-zero error code, gzip ignores that, compresses nothing, and returns success (zero error code). The consequence of this behavior is that when the git version provided in the package is incorrect, we are not failing during the download step, but later on when trying to extract the tarball (which was incorrectly created as a result of the failing git archive).

To fix this, we change the tarball creation logic to:

git archive -o <tarball>.tmp <version> &&
gzip -c <tarball>.tmp > <tarball> &&
rm -f <tarball>.tmp

If the build is interrupted during the "gzip" command, we may leave the .tmp file behind us, but this also happens with wget downloads, and is generally not considered a problem, since this temporary file will be overwritten next time we attempt to do download this package.

---
 package/pkg-download.mk | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
package/pkg-download.mk +3 -2
index c00689b..2641d4e 100644
@@ -91,8 +91,9 @@ define DOWNLOAD_GIT
 	  (echo "Doing full clone" && \
 	   $(GIT) clone --bare $($(PKG)_SITE) $($(PKG)_BASE_NAME))) && \
 	pushd $($(PKG)_BASE_NAME) > /dev/null && \
-	$(GIT) archive --format=tar --prefix=$($(PKG)_BASE_NAME)/ $($(PKG)_DL_VERSION) | \
-		gzip -c > $(DL_DIR)/$($(PKG)_SOURCE) && \
+	$(GIT) archive --format=tar --prefix=$($(PKG)_BASE_NAME)/ -o $(DL_DIR)/.$($(PKG)_SOURCE).tmp $($(PKG)_DL_VERSION) && \
+	gzip -c $(DL_DIR)/.$($(PKG)_SOURCE).tmp > $(DL_DIR)/$($(PKG)_SOURCE) && \
+	rm -f $(DL_DIR)/.$($(PKG)_SOURCE).tmp && \
 	popd > /dev/null && \
 	rm -rf $($(PKG)_DL_DIR) && \
 	popd > /dev/null)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/1 pkg-download: make sure git downloads fail for unknown versions

Quoted 19 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas Petazzoni <[email protected]> writes:

The current git download helper creates the tarball by doing:
git archive <version> | gzip -c > <tarball>

Unfortunately, even if "git archive" fails and returns a non-zero error code, gzip ignores that, compresses nothing, and returns success (zero error code). The consequence of this behavior is that when the git version provided in the package is incorrect, we are not failing during the download step, but later on when trying to extract the tarball (which was incorrectly created as a result of the failing git archive).

To fix this, we change the tarball creation logic to:

   git archive -o <tarball>.tmp <version> &&
   gzip -c <tarball>.tmp > <tarball> &&
   rm -f <tarball>.tmp
Quoted 7 lines

If the build is interrupted during the "gzip" command, we may leave the .tmp file behind us, but this also happens with wget downloads, and is generally not considered a problem, since this temporary file will be overwritten next time we attempt to do download this package.

This could probably be handled without a temporary file using bash's pipefail support, but as we're planning on moving the download helpers to seperate shell scripts .. - Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard