Subject: pkg/36473: Postpone ${DISTDIR} write permission check till it's really needed
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Aleksej Saushev <asau@hotbox.ru>
List: pkgsrc-bugs
Date: 06/11/2007 19:10:00
>Number:         36473
>Category:       pkg
>Synopsis:       Postpone ${DISTDIR} write permission check till it's really needed
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 11 19:10:00 +0000 2007
>Originator:     Aleksej Saushev <asau@hotbox.ru>
>Release:        NetBSD 4.99.20
>Organization:
>Environment:
System: NetBSD asau.local 4.99.20 NetBSD 4.99.20 (KERN) #26: Wed Jun 6 00:48:33 MSD 2007 root@asau.local:/usr/obj/sys/arch/i386/compile/KERN i386
Architecture: i386
Machine: i386
>Description:

When write permission is checked after it's made sure
distribution file is missing, it becomes possible to use the
same DISTDIR for private pkgsrc tree in more convenient way.
It allows building from read-only DISTDIR.
The regular user is no longer forced to create links into
"system-wide" DISTDIR nor to loose his efforts just to make
separate custom installation of ported software. 

>How-To-Repeat:
>Fix:

Apply patch below:

--- mk/fetch/fetch.orig	2007-03-01 14:01:13.000000000 +0300
+++ mk/fetch/fetch	2007-06-11 15:16:23.000000000 +0400
@@ -171,12 +171,6 @@
 	exit 1
 fi
 
-${TEST} -d $fetchdir || ${MKDIR} -p $fetchdir 2>/dev/null
-if ${TEST} ! -w $fetchdir; then
-	${ECHO} 1>&2 "$self: Cannot write to `cd $fetchdir && pwd`"
-	exit 1
-fi
-
 # Compute the expected size of the fetched file.
 distsize=
 distunits=
@@ -223,6 +217,12 @@
 	exit 0
 fi
 
+${TEST} -d $fetchdir || ${MKDIR} -p $fetchdir 2>/dev/null
+if ${TEST} ! -w $fetchdir; then
+	${ECHO} 1>&2 "$self: Cannot write to `cd $fetchdir && pwd`"
+	exit 1
+fi
+
 # Set the name of the output file.  In the "resume" case, we initialize
 # the fetch loop by ensuring that the temporary output file already
 # exists.