Adding xbps_fetch_file_dest().
This function is similiar to xbps_fetch_file(). In contrast to xbps_fetch_file() xbps_fetch_file_dest has an extra paramenter which allow to define an output file for the request.
This commit is contained in:
parent
f20694a5bf
commit
59ee6b6733
@ -670,6 +670,20 @@ int xbps_configure_packages(struct xbps_handle *xhp, bool flush);
|
|||||||
int xbps_fetch_file(struct xbps_handle *xhp, const char *uri,
|
int xbps_fetch_file(struct xbps_handle *xhp, const char *uri,
|
||||||
const char *flags);
|
const char *flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download a file from a remote URL to current working directory.
|
||||||
|
*
|
||||||
|
* @param[in] xhp Pointer to an xbps_handle struct.
|
||||||
|
* @param[in] uri Remote URI string.
|
||||||
|
* @param[in] filename Local filename to safe the file
|
||||||
|
* @param[in] flags Flags passed to libfetch's fetchXget().
|
||||||
|
*
|
||||||
|
* @return -1 on error, 0 if not downloaded (because local/remote size/mtime
|
||||||
|
* do not match) and 1 if downloaded successfully.
|
||||||
|
**/
|
||||||
|
int xbps_fetch_file_dest(struct xbps_handle *xhp, const char *uri,
|
||||||
|
const char *filename, const char *flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns last error string reported by xbps_fetch_file().
|
* Returns last error string reported by xbps_fetch_file().
|
||||||
*
|
*
|
||||||
|
@ -91,7 +91,7 @@ xbps_fetch_error_string(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xbps_fetch_file(struct xbps_handle *xhp, const char *uri, const char *flags)
|
xbps_fetch_file_dest(struct xbps_handle *xhp, const char *uri, const char *filename, const char *flags)
|
||||||
{
|
{
|
||||||
struct stat st, st_tmpfile, *stp;
|
struct stat st, st_tmpfile, *stp;
|
||||||
struct url *url = NULL;
|
struct url *url = NULL;
|
||||||
@ -100,7 +100,7 @@ xbps_fetch_file(struct xbps_handle *xhp, const char *uri, const char *flags)
|
|||||||
struct timespec ts[2];
|
struct timespec ts[2];
|
||||||
off_t bytes_dload = 0;
|
off_t bytes_dload = 0;
|
||||||
ssize_t bytes_read = 0, bytes_written = 0;
|
ssize_t bytes_read = 0, bytes_written = 0;
|
||||||
char buf[4096], *filename, *tempfile = NULL;
|
char buf[4096], *tempfile = NULL;
|
||||||
char fetch_flags[8];
|
char fetch_flags[8];
|
||||||
int fd = -1, rv = 0;
|
int fd = -1, rv = 0;
|
||||||
bool refetch = false, restart = false;
|
bool refetch = false, restart = false;
|
||||||
@ -117,14 +117,6 @@ xbps_fetch_file(struct xbps_handle *xhp, const char *uri, const char *flags)
|
|||||||
memset(&fetch_flags, 0, sizeof(fetch_flags));
|
memset(&fetch_flags, 0, sizeof(fetch_flags));
|
||||||
if (flags != NULL)
|
if (flags != NULL)
|
||||||
strlcpy(fetch_flags, flags, 7);
|
strlcpy(fetch_flags, flags, 7);
|
||||||
/*
|
|
||||||
* Get the filename specified in URI argument.
|
|
||||||
*/
|
|
||||||
filename = strrchr(uri, '/') + 1;
|
|
||||||
if (filename == NULL) {
|
|
||||||
rv = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
tempfile = xbps_xasprintf("%s.part", filename);
|
tempfile = xbps_xasprintf("%s.part", filename);
|
||||||
/*
|
/*
|
||||||
@ -298,3 +290,18 @@ out:
|
|||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
int
|
||||||
|
xbps_fetch_file(struct xbps_handle *xhp, const char *uri, const char *flags)
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the filename specified in URI argument.
|
||||||
|
*/
|
||||||
|
filename = strrchr(uri, '/') + 1;
|
||||||
|
if (filename == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return xbps_fetch_file_dest(xhp, uri, filename, flags);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user