[pacman-dev,1/2] libmakepkg: Fix handling of file paths in get_filepath

Message ID 20180428093108.8263-2-archlinux@thecybershadow.net
State Changes Requested
Headers show
Series
  • makepkg: Allow placing local sources in subdirectories
Related show

Commit Message

Vladimir Panteleev April 28, 2018, 9:31 a.m. UTC
With local sources containing a path component, get_filepath used to
silently discard the non-filename part of the source URI, which led to
uninformative errors (as well as not being able to place source files
in a subdirectory).

Correct this bug by explicitly adding a case for the local protocol,
and appropriately resolve file paths (local or global) to an absolute
one usable by extract_file.
---
 scripts/libmakepkg/util/source.sh.in | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Patch

diff --git a/scripts/libmakepkg/util/source.sh.in b/scripts/libmakepkg/util/source.sh.in
index 17e44664..5092347d 100644
--- a/scripts/libmakepkg/util/source.sh.in
+++ b/scripts/libmakepkg/util/source.sh.in
@@ -85,8 +85,9 @@  get_filename() {
 
 # Return the absolute filename of a source entry
 get_filepath() {
-	local file="$(get_filename "$1")"
-	local proto="$(get_protocol "$1")"
+	local netfile="$1"
+	local file="$(get_filename "$netfile")"
+	local proto="$(get_protocol "$netfile")"
 
 	case $proto in
 		bzr*|git*|hg*|svn*)
@@ -98,6 +99,23 @@  get_filepath() {
 				return 1
 			fi
 			;;
+		local)
+			if [[ "$netfile" == /* ]]; then
+				# absolute path
+				if [[ -f "$netfile" ]]; then
+					file="$netfile"
+				else
+					return 1
+				fi
+			elif [[ -f "$startdir/$netfile" ]]; then
+				# relative path
+				file="$startdir/$netfile"
+			elif [[ -f "$SRCDEST/$netfile" ]]; then
+				file="$SRCDEST/$netfile"
+			else
+				return 1
+			fi
+			;;
 		*)
 			if [[ -f "$startdir/$file" ]]; then
 				file="$startdir/$file"