From c51d82f8f616c2c8939b74c1d78f723ef778f0c8 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 18 Jun 2013 07:52:23 +0000
Subject: url: fix fetching from local repositories

---
 src/apk_io.h | 5 +++--
 src/url.c    | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/apk_io.h b/src/apk_io.h
index 76165b7..c61fc6e 100644
--- a/src/apk_io.h
+++ b/src/apk_io.h
@@ -13,6 +13,7 @@
 
 #include <sys/types.h>
 #include <openssl/evp.h>
+#include <fcntl.h>
 
 #include "apk_defines.h"
 #include "apk_blob.h"
@@ -91,7 +92,7 @@ static inline struct apk_istream *apk_istream_from_fd(int fd)
 }
 static inline struct apk_istream *apk_istream_from_url(const char *url)
 {
-	return apk_istream_from_fd_url(-1, url);
+	return apk_istream_from_fd_url(AT_FDCWD, url);
 }
 
 struct apk_bstream *apk_bstream_from_istream(struct apk_istream *istream);
@@ -108,7 +109,7 @@ static inline struct apk_bstream *apk_bstream_from_fd(int fd)
 
 static inline struct apk_bstream *apk_bstream_from_url(const char *url)
 {
-	return apk_bstream_from_fd_url(-1, url);
+	return apk_bstream_from_fd_url(AT_FDCWD, url);
 }
 
 struct apk_ostream *apk_ostream_to_fd(int fd);
diff --git a/src/url.c b/src/url.c
index 8012bab..974fc54 100644
--- a/src/url.c
+++ b/src/url.c
@@ -91,7 +91,7 @@ struct apk_istream *apk_istream_from_fd_url(int atfd, const char *url)
 	pid_t pid;
 	int fd;
 
-	if (atfd >= 0 && apk_url_local_file(url) != NULL)
+	if (apk_url_local_file(url) != NULL)
 		return apk_istream_from_file(atfd, apk_url_local_file(url));
 
 	fd = fork_wget(url, &pid);
@@ -108,8 +108,8 @@ struct apk_bstream *apk_bstream_from_fd_url(int atfd, const char *url)
 	pid_t pid;
 	int fd;
 
-	if (atfd >= 0 && apk_url_local_file(url))
-		return apk_bstream_from_file(atfd, url);
+	if (apk_url_local_file(url) != NULL)
+		return apk_bstream_from_file(atfd, apk_url_local_file(url));
 
 	fd = fork_wget(url, &pid);
 	return apk_bstream_from_fd_pid(fd, pid, translate_wget);
-- 
cgit v1.2.3-70-g09d2