2009-10-27 06:16:00 +05:30
|
|
|
/*-
|
2013-02-20 15:16:21 +05:30
|
|
|
* Copyright (c) 2009-2013 Juan Romero Pardines
|
2009-10-27 06:16:00 +05:30
|
|
|
* Copyright (c) 2000-2004 Dag-Erling Coïdan Smørgrav
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* From FreeBSD fetch(8):
|
|
|
|
* $FreeBSD: src/usr.bin/fetch/fetch.c,v 1.84.2.1 2009/08/03 08:13:06 kensmith Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2014-08-11 22:10:44 +05:30
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <libgen.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2019-07-07 17:37:59 +05:30
|
|
|
#include <openssl/sha.h>
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-10-27 06:16:00 +05:30
|
|
|
#include "fetch.h"
|
2013-01-13 20:57:59 +05:30
|
|
|
#include "compat.h"
|
2009-10-27 06:16:00 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
|
|
|
* @file lib/download.c
|
|
|
|
* @brief Download routines
|
2011-01-22 18:54:51 +05:30
|
|
|
* @defgroup download Download functions
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2011-01-22 18:54:51 +05:30
|
|
|
* XBPS download related functions, frontend for NetBSD's libfetch.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
2009-10-31 19:39:25 +05:30
|
|
|
static const char *
|
|
|
|
print_time(time_t *t)
|
|
|
|
{
|
|
|
|
struct tm tm;
|
|
|
|
static char buf[255];
|
|
|
|
|
2013-01-13 20:57:59 +05:30
|
|
|
gmtime_r(t, &tm);
|
2009-10-31 19:39:25 +05:30
|
|
|
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
|
|
|
|
return buf;
|
|
|
|
}
|
2010-01-24 20:18:29 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
void HIDDEN
|
2010-01-24 20:18:29 +05:30
|
|
|
xbps_fetch_set_cache_connection(int global, int per_host)
|
|
|
|
{
|
|
|
|
if (global == 0)
|
2010-01-24 21:01:56 +05:30
|
|
|
global = XBPS_FETCH_CACHECONN;
|
2010-01-24 20:18:29 +05:30
|
|
|
if (per_host == 0)
|
2010-01-24 21:01:56 +05:30
|
|
|
per_host = XBPS_FETCH_CACHECONN_HOST;
|
2010-01-24 20:18:29 +05:30
|
|
|
|
|
|
|
fetchConnectionCacheInit(global, per_host);
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
void HIDDEN
|
2010-11-03 16:53:57 +05:30
|
|
|
xbps_fetch_unset_cache_connection(void)
|
|
|
|
{
|
|
|
|
fetchConnectionCacheClose();
|
|
|
|
}
|
|
|
|
|
2011-01-22 17:10:19 +05:30
|
|
|
const char *
|
|
|
|
xbps_fetch_error_string(void)
|
|
|
|
{
|
2011-11-11 05:00:01 +05:30
|
|
|
if (fetchLastErrCode == 0 || fetchLastErrCode == FETCH_OK)
|
|
|
|
return NULL;
|
|
|
|
|
2011-01-22 17:10:19 +05:30
|
|
|
return fetchLastErrString;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2020-02-10 06:24:52 +05:30
|
|
|
xbps_fetch_file_dest_sha256(struct xbps_handle *xhp, const char *uri, const char *filename, const char *flags, unsigned char *digest, size_t digestlen)
|
2009-10-27 06:16:00 +05:30
|
|
|
{
|
2012-11-11 15:59:49 +05:30
|
|
|
struct stat st, st_tmpfile, *stp;
|
2009-10-27 06:16:00 +05:30
|
|
|
struct url *url = NULL;
|
|
|
|
struct url_stat url_st;
|
|
|
|
struct fetchIO *fio = NULL;
|
2012-11-11 15:59:49 +05:30
|
|
|
struct timespec ts[2];
|
2013-01-13 20:57:59 +05:30
|
|
|
off_t bytes_dload = 0;
|
|
|
|
ssize_t bytes_read = 0, bytes_written = 0;
|
2014-03-04 18:49:52 +05:30
|
|
|
char buf[4096], *tempfile = NULL;
|
2013-01-13 20:57:59 +05:30
|
|
|
char fetch_flags[8];
|
2009-10-27 06:16:00 +05:30
|
|
|
int fd = -1, rv = 0;
|
2012-11-11 15:59:49 +05:30
|
|
|
bool refetch = false, restart = false;
|
2019-07-07 17:37:59 +05:30
|
|
|
SHA256_CTX sha256;
|
2009-10-27 06:16:00 +05:30
|
|
|
|
2012-11-11 15:59:49 +05:30
|
|
|
assert(xhp);
|
|
|
|
assert(uri);
|
2011-01-25 08:44:33 +05:30
|
|
|
|
2020-02-10 18:38:39 +05:30
|
|
|
if (digest != NULL) {
|
|
|
|
assert(digestlen >= XBPS_SHA256_DIGEST_SIZE);
|
|
|
|
if (digestlen < XBPS_SHA256_DIGEST_SIZE) {
|
|
|
|
errno = ENOBUFS;
|
|
|
|
return -1;
|
|
|
|
}
|
2019-07-07 17:37:59 +05:30
|
|
|
SHA256_Init(&sha256);
|
|
|
|
}
|
|
|
|
|
2012-11-11 15:59:49 +05:30
|
|
|
/* Extern vars declared in libfetch */
|
2009-10-30 21:50:44 +05:30
|
|
|
fetchLastErrCode = 0;
|
2013-01-13 20:57:59 +05:30
|
|
|
|
2014-10-05 15:43:34 +05:30
|
|
|
if (!filename || (url = fetchParseURL(uri)) == NULL)
|
2013-01-13 20:57:59 +05:30
|
|
|
return -1;
|
|
|
|
|
2013-11-26 15:01:16 +05:30
|
|
|
memset(&fetch_flags, 0, sizeof(fetch_flags));
|
2013-01-15 20:25:18 +05:30
|
|
|
if (flags != NULL)
|
2016-04-17 23:47:37 +05:30
|
|
|
xbps_strlcpy(fetch_flags, flags, 7);
|
2011-01-22 17:10:19 +05:30
|
|
|
|
2012-11-11 15:59:49 +05:30
|
|
|
tempfile = xbps_xasprintf("%s.part", filename);
|
2009-10-27 06:16:00 +05:30
|
|
|
/*
|
2012-11-11 15:59:49 +05:30
|
|
|
* Check if we have to resume a transfer.
|
2009-10-27 06:16:00 +05:30
|
|
|
*/
|
2013-11-26 15:01:16 +05:30
|
|
|
memset(&st_tmpfile, 0, sizeof(st_tmpfile));
|
2012-11-11 15:59:49 +05:30
|
|
|
if (stat(tempfile, &st_tmpfile) == 0) {
|
|
|
|
if (st_tmpfile.st_size > 0)
|
|
|
|
restart = true;
|
|
|
|
} else {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2012-11-11 15:59:49 +05:30
|
|
|
}
|
|
|
|
}
|
2009-10-30 21:50:44 +05:30
|
|
|
/*
|
2012-11-11 15:59:49 +05:30
|
|
|
* Check if we have to refetch a transfer.
|
2009-10-30 21:50:44 +05:30
|
|
|
*/
|
2013-11-26 15:01:16 +05:30
|
|
|
memset(&st, 0, sizeof(st));
|
2012-11-11 15:59:49 +05:30
|
|
|
if (stat(filename, &st) == 0) {
|
|
|
|
refetch = true;
|
2013-01-13 20:57:59 +05:30
|
|
|
url->last_modified = st.st_mtime;
|
2016-04-17 23:47:37 +05:30
|
|
|
xbps_strlcat(fetch_flags, "i", sizeof(fetch_flags));
|
2009-11-18 11:58:14 +05:30
|
|
|
} else {
|
2009-10-27 06:16:00 +05:30
|
|
|
if (errno != ENOENT) {
|
2009-11-24 10:33:26 +05:30
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
|
|
|
}
|
2013-01-13 20:57:59 +05:30
|
|
|
if (refetch && !restart) {
|
|
|
|
/* fetch the whole file, filename available */
|
2012-11-11 15:59:49 +05:30
|
|
|
stp = &st;
|
2009-11-18 11:58:14 +05:30
|
|
|
} else {
|
2013-01-13 20:57:59 +05:30
|
|
|
/* resume transfer, partial file found */
|
2012-11-11 15:59:49 +05:30
|
|
|
stp = &st_tmpfile;
|
|
|
|
url->offset = stp->st_size;
|
2009-11-18 11:58:14 +05:30
|
|
|
}
|
2013-01-13 20:57:59 +05:30
|
|
|
/*
|
|
|
|
* Issue a GET request.
|
|
|
|
*/
|
|
|
|
fio = fetchXGet(url, &url_st, fetch_flags);
|
2009-10-31 19:39:25 +05:30
|
|
|
|
2011-01-22 17:10:19 +05:30
|
|
|
/* debug stuff */
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("st.st_size: %zd\n", (ssize_t)stp->st_size);
|
|
|
|
xbps_dbg_printf("st.st_atime: %s\n", print_time(&stp->st_atime));
|
|
|
|
xbps_dbg_printf("st.st_mtime: %s\n", print_time(&stp->st_mtime));
|
|
|
|
xbps_dbg_printf("url_stat.size: %zd\n", (ssize_t)url_st.size);
|
|
|
|
xbps_dbg_printf("url_stat.atime: %s\n", print_time(&url_st.atime));
|
|
|
|
xbps_dbg_printf("url_stat.mtime: %s\n", print_time(&url_st.mtime));
|
2009-10-31 19:39:25 +05:30
|
|
|
|
2013-01-13 20:57:59 +05:30
|
|
|
if (fio == NULL) {
|
|
|
|
if (fetchLastErrCode == FETCH_UNCHANGED) {
|
|
|
|
/* Last-Modified matched */
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2015-06-28 07:58:55 +05:30
|
|
|
} else if (fetchLastErrCode == FETCH_PROTO && url_st.size == stp->st_size) {
|
|
|
|
/* 413, requested offset == length */
|
|
|
|
goto rename_file;
|
2009-11-07 10:51:01 +05:30
|
|
|
}
|
2009-11-24 10:33:26 +05:30
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2009-10-31 19:39:25 +05:30
|
|
|
if (url_st.size == -1) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("Remote file size is unknown, resume "
|
2012-01-05 16:56:57 +05:30
|
|
|
"not possible...\n");
|
|
|
|
restart = false;
|
2012-11-11 15:59:49 +05:30
|
|
|
} else if (stp->st_size > url_st.size) {
|
2011-06-23 03:36:50 +05:30
|
|
|
/*
|
|
|
|
* Remove local file if bigger than remote, and refetch the
|
|
|
|
* whole shit again.
|
|
|
|
*/
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("Local file %s is greater than remote, "
|
2011-06-23 03:36:50 +05:30
|
|
|
"removing local file and refetching...\n", filename);
|
2012-11-11 15:59:49 +05:30
|
|
|
(void)remove(tempfile);
|
|
|
|
restart = false;
|
2009-10-30 21:50:44 +05:30
|
|
|
}
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("url->scheme: %s\n", url->scheme);
|
|
|
|
xbps_dbg_printf("url->host: %s\n", url->host);
|
|
|
|
xbps_dbg_printf("url->port: %d\n", url->port);
|
|
|
|
xbps_dbg_printf("url->doc: %s\n", url->doc);
|
|
|
|
xbps_dbg_printf("url->offset: %zd\n", (ssize_t)url->offset);
|
|
|
|
xbps_dbg_printf("url->length: %zu\n", url->length);
|
|
|
|
xbps_dbg_printf("url->last_modified: %s\n",
|
2014-09-07 13:15:47 +05:30
|
|
|
print_time(&url->last_modified));
|
2009-10-27 06:16:00 +05:30
|
|
|
/*
|
|
|
|
* If restarting, open the file for appending otherwise create it.
|
|
|
|
*/
|
|
|
|
if (restart)
|
2020-01-18 21:03:58 +05:30
|
|
|
fd = open(tempfile, O_RDWR|O_CLOEXEC);
|
2009-10-27 06:16:00 +05:30
|
|
|
else
|
2012-12-15 14:20:37 +05:30
|
|
|
fd = open(tempfile, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC, 0644);
|
2009-10-27 06:16:00 +05:30
|
|
|
|
|
|
|
if (fd == -1) {
|
2009-11-24 10:33:26 +05:30
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2020-01-18 21:03:58 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* If restarting and digest was requested, read the current data
|
|
|
|
* and feed into sha256 hash.
|
|
|
|
*/
|
|
|
|
if (restart) {
|
|
|
|
if (digest) {
|
|
|
|
while ((bytes_read = read(fd, buf, sizeof(buf))) > 0) {
|
|
|
|
SHA256_Update(&sha256, buf, bytes_read);
|
|
|
|
}
|
|
|
|
if (bytes_read == -1) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("IO error while reading %s: %s\n",
|
2020-01-18 21:03:58 +05:30
|
|
|
tempfile, strerror(errno));
|
|
|
|
errno = EIO;
|
|
|
|
rv = -1;
|
|
|
|
goto fetch_file_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lseek(fd, 0, SEEK_END);
|
|
|
|
}
|
|
|
|
|
2011-01-22 17:10:19 +05:30
|
|
|
/*
|
|
|
|
* Initialize data for the fetch progress function callback
|
|
|
|
* and let the user know that the transfer is going to start
|
|
|
|
* immediately.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_fetch(xhp, url_st.size, url->offset, url->offset,
|
2011-11-24 15:53:08 +05:30
|
|
|
filename, true, false, false);
|
2009-10-27 06:16:00 +05:30
|
|
|
/*
|
|
|
|
* Start fetching requested file.
|
|
|
|
*/
|
|
|
|
while ((bytes_read = fetchIO_read(fio, buf, sizeof(buf))) > 0) {
|
2019-07-07 17:37:59 +05:30
|
|
|
if (digest)
|
|
|
|
SHA256_Update(&sha256, buf, bytes_read);
|
2009-10-27 06:16:00 +05:30
|
|
|
bytes_written = write(fd, buf, (size_t)bytes_read);
|
|
|
|
if (bytes_written != bytes_read) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("Couldn't write to %s!\n", tempfile);
|
2009-11-24 10:33:26 +05:30
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2011-01-22 17:10:19 +05:30
|
|
|
bytes_dload += bytes_read;
|
|
|
|
/*
|
|
|
|
* Let the fetch progress callback know that
|
|
|
|
* we are sucking more bytes from it.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_fetch(xhp, url_st.size, url->offset,
|
|
|
|
url->offset + bytes_dload,
|
2011-11-24 15:53:08 +05:30
|
|
|
filename, false, true, false);
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2009-10-31 16:10:55 +05:30
|
|
|
if (bytes_read == -1) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("IO error while fetching %s: %s\n",
|
2012-11-11 15:59:49 +05:30
|
|
|
filename, fetchLastErrString);
|
2009-11-24 10:33:26 +05:30
|
|
|
errno = EIO;
|
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2013-02-01 18:10:27 +05:30
|
|
|
} else if (url_st.size > 0 && ((bytes_dload + url->offset) != url_st.size)) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("file %s is truncated\n", filename);
|
2013-01-13 20:57:59 +05:30
|
|
|
errno = EIO;
|
2011-01-22 17:10:19 +05:30
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2011-01-22 17:10:19 +05:30
|
|
|
}
|
2013-01-13 20:57:59 +05:30
|
|
|
|
2011-11-24 15:53:08 +05:30
|
|
|
/*
|
|
|
|
* Let the fetch progress callback know that the file
|
|
|
|
* has been fetched.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_fetch(xhp, url_st.size, url->offset, bytes_dload,
|
2011-11-24 15:53:08 +05:30
|
|
|
filename, false, false, true);
|
2015-06-28 07:58:55 +05:30
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
/*
|
2009-11-18 11:58:14 +05:30
|
|
|
* Update mtime in local file to match remote file if transfer
|
|
|
|
* was successful.
|
2009-10-27 06:16:00 +05:30
|
|
|
*/
|
2012-11-11 15:59:49 +05:30
|
|
|
ts[0].tv_sec = url_st.atime ? url_st.atime : url_st.mtime;
|
|
|
|
ts[1].tv_sec = url_st.mtime;
|
|
|
|
ts[0].tv_nsec = ts[1].tv_nsec = 0;
|
|
|
|
if (futimens(fd, ts) == -1) {
|
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2012-11-11 15:59:49 +05:30
|
|
|
}
|
|
|
|
(void)close(fd);
|
2013-01-13 20:57:59 +05:30
|
|
|
fd = -1;
|
2012-11-11 15:59:49 +05:30
|
|
|
|
2015-06-28 07:58:55 +05:30
|
|
|
rename_file:
|
2012-11-11 15:59:49 +05:30
|
|
|
/* File downloaded successfully, rename to destfile */
|
|
|
|
if (rename(tempfile, filename) == -1) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("failed to rename %s to %s: %s",
|
2012-11-11 15:59:49 +05:30
|
|
|
tempfile, filename, strerror(errno));
|
2009-11-24 10:33:26 +05:30
|
|
|
rv = -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
goto fetch_file_out;
|
2009-11-24 10:33:26 +05:30
|
|
|
}
|
2011-01-22 17:10:19 +05:30
|
|
|
rv = 1;
|
|
|
|
|
2020-02-10 06:24:52 +05:30
|
|
|
if (digest)
|
2019-07-07 17:37:59 +05:30
|
|
|
SHA256_Final(digest, &sha256);
|
|
|
|
|
2014-08-11 22:10:44 +05:30
|
|
|
fetch_file_out:
|
2009-11-07 10:51:01 +05:30
|
|
|
if (fio != NULL)
|
2009-10-27 06:16:00 +05:30
|
|
|
fetchIO_close(fio);
|
2013-01-13 20:57:59 +05:30
|
|
|
if (fd != -1)
|
|
|
|
(void)close(fd);
|
2009-11-07 10:51:01 +05:30
|
|
|
if (url != NULL)
|
2009-10-27 06:16:00 +05:30
|
|
|
fetchFreeURL(url);
|
2014-10-06 11:53:34 +05:30
|
|
|
|
|
|
|
free(tempfile);
|
2009-10-27 06:16:00 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2014-08-11 22:10:44 +05:30
|
|
|
|
2014-03-04 18:49:52 +05:30
|
|
|
int
|
2019-07-07 17:37:59 +05:30
|
|
|
xbps_fetch_file_dest(struct xbps_handle *xhp, const char *uri,
|
|
|
|
const char *filename, const char *flags)
|
|
|
|
{
|
2020-02-10 06:24:52 +05:30
|
|
|
return xbps_fetch_file_dest_sha256(xhp, uri, filename, flags, NULL, 0);
|
2019-07-07 17:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-10 06:24:52 +05:30
|
|
|
xbps_fetch_file_sha256(struct xbps_handle *xhp, const char *uri,
|
|
|
|
const char *flags, unsigned char *digest, size_t digestlen)
|
2014-03-04 18:49:52 +05:30
|
|
|
{
|
2014-10-24 14:34:51 +05:30
|
|
|
const char *filename;
|
2014-03-04 18:49:52 +05:30
|
|
|
/*
|
|
|
|
* Get the filename specified in URI argument.
|
|
|
|
*/
|
2014-10-24 14:34:51 +05:30
|
|
|
if ((filename = strrchr(uri, '/')) == NULL)
|
|
|
|
return -1;
|
2014-08-11 22:10:44 +05:30
|
|
|
|
2014-10-24 14:34:51 +05:30
|
|
|
filename++;
|
2020-02-10 06:24:52 +05:30
|
|
|
return xbps_fetch_file_dest_sha256(xhp, uri, filename, flags,
|
|
|
|
digest, digestlen);
|
2019-07-07 17:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xbps_fetch_file(struct xbps_handle *xhp, const char *uri, const char *flags)
|
|
|
|
{
|
2020-02-10 06:24:52 +05:30
|
|
|
return xbps_fetch_file_sha256(xhp, uri, flags, NULL, 0);
|
2014-08-11 22:10:44 +05:30
|
|
|
}
|