Introduce xbps_binpkg_get_file_into_fd() and use it for xbps-query(8) --cat.
This allows you to print to stdout any file stored in a binary package, locally or remotely! $ xbps-query -R --cat=/usr/bin/ls coreutils > ls $ file ls ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=7a195fc46d1d5cdca32bfccd3b30f81784e342ed, stripped $
This commit is contained in:
@@ -168,6 +168,39 @@ xbps_binpkg_get_file(const char *url, const char *fname)
|
||||
return buf;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_binpkg_get_file_into_fd(const char *url, const char *fname, int fd)
|
||||
{
|
||||
struct archive *a;
|
||||
struct archive_entry *entry;
|
||||
int rv = 0;
|
||||
|
||||
assert(url);
|
||||
assert(fname);
|
||||
assert(fd != -1);
|
||||
|
||||
if ((a = open_archive(url)) == NULL)
|
||||
return EINVAL;
|
||||
|
||||
while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) {
|
||||
const char *bfile;
|
||||
|
||||
bfile = archive_entry_pathname(entry);
|
||||
bfile++; /* skip first dot */
|
||||
if (strcmp(bfile, fname) == 0) {
|
||||
rv = archive_read_data_into_fd(a, fd);
|
||||
if (rv != 0)
|
||||
rv = archive_errno(a);
|
||||
|
||||
break;
|
||||
}
|
||||
archive_read_data_skip(a);
|
||||
}
|
||||
archive_read_finish(a);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
xbps_dictionary_t
|
||||
xbps_binpkg_get_plist(const char *url, const char *plistf)
|
||||
{
|
||||
|
Reference in New Issue
Block a user