summaryrefslogtreecommitdiff
path: root/src/url.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-04-16 20:05:22 +0300
committerTimo Teras <timo.teras@iki.fi>2009-04-16 20:05:22 +0300
commit4c2bfd9dedab2533cbfc9c2bf4f827eb5f5f51a6 (patch)
tree6d58d85eda5acf760e1dc6d19bbaa3cd68b00baf /src/url.c
parentaaa3c227b85756dd5c338c2cd156935c12a4a013 (diff)
downloadapk-tools-4c2bfd9dedab2533cbfc9c2bf4f827eb5f5f51a6.tar.gz
apk-tools-4c2bfd9dedab2533cbfc9c2bf4f827eb5f5f51a6.tar.bz2
apk-tools-4c2bfd9dedab2533cbfc9c2bf4f827eb5f5f51a6.tar.xz
apk-tools-4c2bfd9dedab2533cbfc9c2bf4f827eb5f5f51a6.zip
db: cache index files, 'update' applet
Cache non-local index files always locally. Introduce 'update' applet to force refresh of cached index files. Fixes #19.
Diffstat (limited to 'src/url.c')
-rw-r--r--src/url.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/url.c b/src/url.c
index 656aef6..8502b28 100644
--- a/src/url.c
+++ b/src/url.c
@@ -13,10 +13,11 @@
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/wait.h>
#include "apk_io.h"
-static const char *url_is_file(const char *url)
+const char *apk_url_local_file(const char *url)
{
if (strncmp(url, "file:", 5) == 0)
return &url[5];
@@ -59,8 +60,8 @@ static int fork_wget(const char *url)
struct apk_istream *apk_istream_from_url(const char *url)
{
- if (url_is_file(url) != NULL)
- return apk_istream_from_file(url_is_file(url));
+ if (apk_url_local_file(url) != NULL)
+ return apk_istream_from_file(apk_url_local_file(url));
return apk_istream_from_fd(fork_wget(url));
}
@@ -72,9 +73,34 @@ struct apk_istream *apk_istream_from_url_gz(const char *file)
struct apk_bstream *apk_bstream_from_url(const char *url)
{
- if (url_is_file(url))
+ if (apk_url_local_file(url))
return apk_bstream_from_file(url);
return apk_bstream_from_fd(fork_wget(url));
}
+int apk_url_download(const char *url, const char *file)
+{
+ pid_t pid;
+ int status;
+
+ pid = fork();
+ if (pid == -1)
+ return -1;
+
+ if (pid == 0) {
+ setsid();
+ dup2(open("/dev/null", O_RDONLY), STDIN_FILENO);
+ execlp("wget", "wget", "-q", "-O", file, url, NULL);
+ exit(0);
+ }
+
+ waitpid(pid, &status, 0);
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ unlink(file);
+ return -1;
+ }
+
+ return 0;
+}
+