aboutsummaryrefslogtreecommitdiffstats
path: root/libopkg/opkg_download_wget.c
blob: 3dec766f9add4ac647f421cb8bda1801e189a574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* vi: set expandtab sw=4 sts=4: */
/* opkg_download_wget.c - the opkg package management system

   Copyright (C) 2001 University of Southern California
   Copyright (C) 2008 OpenMoko Inc
   Copyright (C) 2014 Paul Barker

   SPDX-License-Identifier: GPL-2.0-or-later

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
*/

#include "config.h"

#include <unistd.h>

#include "opkg_download.h"
#include "opkg_message.h"
#include "xsystem.h"

/* Download using wget backend.
 *
 * This backend should be as simple and minimalistic as possible. If users want
 * things like efficient caching and resuming of downloads they should use the
 * curl backend instead. By keeping the wget backend small, we can satisfy users
 * who want opkg to use very little memory.
 *
 * Both the gnu and busybox versions of wget must be supported by this backend,
 * so we are precluded from using most features anyway.
 */
int opkg_download_backend(const char *src, const char *dest,
                          curl_progress_func cb, void *data, int use_cache)
{
    int res;
    const char *argv[8];
    int i = 0;

    /* Unused arguments. */
    (void)cb;
    (void)data;
    (void)use_cache;

    unlink(dest);

    argv[i++] = "wget";
    argv[i++] = "-q";
    if (opkg_config->http_proxy || opkg_config->ftp_proxy) {
        argv[i++] = "-Y";
        argv[i++] = "on";
    }
    argv[i++] = "-O";
    argv[i++] = dest;
    argv[i++] = src;
    argv[i++] = NULL;
    res = xsystem(argv);

    if (res) {
        opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res);
        return -1;
    }

    return 0;
}

void opkg_download_cleanup(void)
{
    /* Nothing to do. */
}