Browse Source

dpkg-maintscript-helper: Handle empty versions as they are optional arguments

Regression introduced in commit b51bc4ff0cd540b82e131470053eeed1c3d2f026.

Closes: #848422
Guillem Jover 7 years ago
parent
commit
0b8cb1a8ed
2 changed files with 16 additions and 4 deletions
  1. 2 0
      debian/changelog
  2. 14 4
      scripts/dpkg-maintscript-helper.sh

+ 2 - 0
debian/changelog

@@ -1,6 +1,8 @@
 dpkg (1.18.17) UNRELEASED; urgency=medium
 
   [ Guillem Jover ]
+  * Handle empty versions on validation in dpkg-maintscript-helper as they
+    are optional. Regression introduced in dpkg 1.18.16. Closes: #848422
   * Documentation:
     - Clarify that dpkg-buildpackage does not run «dpkg-source --before-build»
       when using the -T option. Closes: #649531

+ 14 - 4
scripts/dpkg-maintscript-helper.sh

@@ -48,8 +48,7 @@ rm_conffile() {
 		error "environment variable DPKG_MAINTSCRIPT_NAME is required"
 	[ "${CONFFILE}" != "${CONFFILE#/}" ] || \
 		error "conffile '$CONFFILE' is not an absolute path"
-	VERSIONCHECK=$(dpkg --validate-version -- "$LASTVERSION" 2>&1) || \
-		error "$VERSIONCHECK"
+	validate_optional_version "$LASTVERSION"
 
 	debug "Executing $0 rm_conffile in $DPKG_MAINTSCRIPT_NAME" \
 	      "of $DPKG_MAINTSCRIPT_PACKAGE"
@@ -161,8 +160,7 @@ mv_conffile() {
 		error "old-conffile '$OLDCONFFILE' is not an absolute path"
 	[ "${NEWCONFFILE}" != "${NEWCONFFILE#/}" ] || \
 		error "new-conffile '$NEWCONFFILE' is not an absolute path"
-	VERSIONCHECK=$(dpkg --validate-version -- "$LASTVERSION" 2>&1) || \
-		error "$VERSIONCHECK"
+	validate_optional_version "$LASTVERSION"
 
 	debug "Executing $0 mv_conffile in $DPKG_MAINTSCRIPT_NAME" \
 	      "of $DPKG_MAINTSCRIPT_PACKAGE"
@@ -493,6 +491,18 @@ abort_dir_to_symlink()
 }
 
 # Common functions
+validate_optional_version() {
+	local VERSION="$1"
+
+	if [ -z "$VERSION" ]; then
+		return
+	fi
+
+	if ! VERSIONCHECK=$(dpkg --validate-version -- "$VERSION" 2>&1); then
+		error "$VERSIONCHECK"
+	fi
+}
+
 ensure_package_owns_file() {
 	local PACKAGE="$1"
 	local FILE="$2"