View | Details | Raw Unified | Return to bug 186671 | Differences between
and this patch

Collapse All | Expand All

(-)ports-mgmt/pkg/files/patch-pkg_version.c (+68 lines)
Line 0 Link Here
1
--- pkg/version.c.orig	2014-02-02 05:33:30.000000000 +1100
2
+++ pkg/version.c	2014-02-15 15:11:37.000000000 +1100
3
@@ -167,6 +167,7 @@
4
 	const char *reponame = NULL;
5
 	const char *version_remote = NULL;
6
 	bool have_ports;
7
+	bool use_arg_index;
8
 	bool auto_update;
9
 	match_t match = MATCH_ALL;
10
 	char *pattern=NULL;
11
@@ -309,16 +310,39 @@
12
 
13
 		have_ports = (stat(portsdirmakefile, &sb) == 0 && S_ISREG(sb.st_mode));
14
 
15
-		/* If none of -IPR were specified, and portsdir exists use that,
16
-		   otherwise fallback to remote. */
17
+		/*
18
+		 * If an index file name has been passed, and neither -P
19
+		 * nor -R were specified, try to use it.  If -I was
20
+		 * specified, a bad index filename is fatal.
21
+		 */
22
+		if (argc == 1 && (opt & (VERSION_SOURCE_PORTS|VERSION_SOURCE_REMOTE)) == 0) {
23
+			snprintf(indexpath, sizeof(indexpath), "%s", argv[0]);
24
+			if (stat(indexpath, &sb) == 0 && S_ISREG(sb.st_mode))
25
+				use_arg_index = true;
26
+			else if (opt & VERSION_SOURCE_INDEX)
27
+				err(1, "Cannot use index %s", indexpath);
28
+			else {
29
+				warn("Ignoring index %s", indexpath);
30
+				use_arg_index = false;
31
+			}
32
+		} else
33
+			use_arg_index = false;
34
+
35
+		/*
36
+		 * If none of -IPR were specified, and portsdir exists use that,
37
+		 * otherwise fallback to remote unless the index file argument
38
+		 * is present and that index file exists.
39
+		 */
40
 		if ((opt & (VERSION_SOURCE_PORTS|VERSION_SOURCE_REMOTE|VERSION_SOURCE_INDEX)) == 0) {
41
 			if (have_ports)
42
 				opt |= VERSION_SOURCE_PORTS;
43
+			else if (use_arg_index)
44
+				opt |= VERSION_SOURCE_INDEX;
45
 			else
46
 				opt |= VERSION_SOURCE_REMOTE;
47
 		}
48
 
49
-		if (!have_ports && (opt & (VERSION_SOURCE_INDEX|VERSION_SOURCE_PORTS)))
50
+		if (!have_ports && (opt & VERSION_SOURCE_PORTS))
51
 			err(1, "Unable to open ports directory %s", portsdir);
52
 
53
 		/* Only force remote mode if looking up remote, otherwise
54
@@ -341,9 +365,11 @@
55
 			goto cleanup;
56
 
57
 		if (opt & VERSION_SOURCE_INDEX) {
58
-			uname(&u);
59
-			rel_major_ver = (int) strtol(u.release, NULL, 10);
60
-			snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
61
+			if (!use_arg_index) {
62
+				uname(&u);
63
+				rel_major_ver = (int) strtol(u.release, NULL, 10);
64
+				snprintf(indexpath, sizeof(indexpath), "%s/INDEX-%d", portsdir, rel_major_ver);
65
+			}
66
 			indexfile = fopen(indexpath, "r");
67
 			if (!indexfile)
68
 				err(EX_SOFTWARE, "Unable to open %s!", indexpath);

Return to bug 186671