This patch fixes the file not found error when multiple sources are
specified that share a base path. 

Signed-off-by: Hugh Greenberg <[email protected]


Index: xget.c
===================================================================
--- xget.c	(revision 750)
+++ xget.c	(working copy)
@@ -1554,7 +1554,7 @@
 {
 	int i;
 	char *s, *p, *nprefix;
-	Spfile *dir;
+	Spfile *dir, *t;
 
 	path = sp_malloc(strlen(fpath) + 1);
 	strcpy(path, fpath);
@@ -1566,21 +1566,30 @@
 
 	for(i = strlen(outname) - 1; i >= 0 && outname[i] == '/'; i--)
 		;
+	
 	outname[i+1] = '\0';
-
+	p = path;
 	dir = root;
-	p = path;
 	if (*p == '/')
 		p++;
 
 	while ((s = strchr(p, '/')) != NULL) {
 		*s = '\0';
-		dir = create_file(dir, p, Dmdir|0770, qpath++ * 16,
-				  &dir_ops, NULL, NULL, NULL);
+		for (t = dir->dirfirst; t != NULL; t = t->next) {
+			if (!strcmp(t->name, p) && t->mode & Dmdir) {
+				dir = t;
+				break;
+			}
+		}
 
-		if (!dir)
+		if (!t)
+			dir = create_file(dir, p, Dmdir|0770, qpath++ * 16,
+					  &dir_ops, NULL, NULL, NULL);
+
+		if (!dir) {
+			free(p);
 			return -1;
-	       
+		}
 
 		*s = '/';
 		p = s + 1;
@@ -1589,11 +1598,22 @@
 	if (p == path)
 		nprefix = "";
 	else {
-		nprefix = path;
+		s = strrchr(path, '/');
+		if (s) {
+		        nprefix = sp_malloc(s - path + 1);
+			snprintf(nprefix, s - path + 1, "%s", path);
+		} else {
+			nprefix = sp_malloc(strlen(path) + 1);
+			strcpy(nprefix, path);
+		}
+
 		*(p-1) = '\0';
 	}
 	
 	i = netread(dir, outname, nprefix, p);
+	if (strlen(nprefix) > 0) 
+		free(nprefix);
+
 	return i;
 }
 
@@ -1796,12 +1816,19 @@
 				goto error;
 			}
 		}
-		
-		if(!S_ISDIR(st.st_mode) && fileargs > 2) {
-			debug(Dbgfn, "Plural sources and nondirectory destination.\n");
-			usage(argv[0]);
+
+		if(!stat(outname, &st)) {
+			if(!S_ISDIR(st.st_mode) && fileargs > 2) {
+				debug(Dbgfn, "Plural sources and nondirectory destination.\n");
+				usage(argv[0]);
+			}
+		} else {
+			sp_uerror(errno);
+			debug(Dbgfn, "Destination does not exist and cannot be created.\n");
+			goto error;
 		}
 
+
 		for(i = optind; i < argc - 1; i++) {
 			dlname = argv[i];
 			if (!strcmp(".", dlname))

Reply via email to