Use cxx-rs for utils.rs download_to_fd
A step towards converting all of utils.
This commit is contained in:
parent
9565c19ef0
commit
8ab6a1f4f0
@ -19,6 +19,11 @@ mod ffi {
|
|||||||
fn prepare_tempetc_guard(rootfs: i32) -> Result<Box<TempEtcGuard>>;
|
fn prepare_tempetc_guard(rootfs: i32) -> Result<Box<TempEtcGuard>>;
|
||||||
fn undo(self: &TempEtcGuard) -> Result<()>;
|
fn undo(self: &TempEtcGuard) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// utils.rs
|
||||||
|
extern "Rust" {
|
||||||
|
fn download_to_fd(url: &str) -> Result<i32>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod cliwrap;
|
mod cliwrap;
|
||||||
|
@ -206,19 +206,8 @@ mod ffi {
|
|||||||
use std::os::unix::io::IntoRawFd;
|
use std::os::unix::io::IntoRawFd;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
#[no_mangle]
|
pub(crate) fn download_to_fd(url: &str) -> Result<i32> {
|
||||||
pub extern "C" fn ror_download_to_fd(
|
download_url_to_tmpfile(url).map(|f| f.into_raw_fd())
|
||||||
url: *const libc::c_char,
|
|
||||||
gerror: *mut *mut glib_sys::GError,
|
|
||||||
) -> libc::c_int {
|
|
||||||
let url: Borrowed<glib::GString> = unsafe { from_glib_borrow(url) };
|
|
||||||
match download_url_to_tmpfile(url.as_str()) {
|
|
||||||
Ok(f) => f.into_raw_fd(),
|
|
||||||
Err(e) => {
|
|
||||||
error_to_glib(&e, gerror);
|
|
||||||
-1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "rpmostree-util.h"
|
#include "rpmostree-util.h"
|
||||||
#include "rpmostree-rpm-util.h"
|
#include "rpmostree-rpm-util.h"
|
||||||
#include "rpmostree-rust.h"
|
#include "rpmostree-rust.h"
|
||||||
|
#include "rpmostree-cxxrs.h"
|
||||||
|
|
||||||
#define RPMOSTREE_CLI_ID "cli"
|
#define RPMOSTREE_CLI_ID "cli"
|
||||||
|
|
||||||
@ -1056,18 +1057,20 @@ rpmostree_sort_pkgs_strv (const char *const* pkgs,
|
|||||||
g_auto(GVariantBuilder) builder;
|
g_auto(GVariantBuilder) builder;
|
||||||
|
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("ah"));
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("ah"));
|
||||||
for (const char *const* pkg = pkgs; pkg && *pkg; pkg++)
|
for (const char *const* pkgiter = pkgs; pkgiter && *pkgiter; pkgiter++)
|
||||||
{
|
{
|
||||||
if (g_str_has_prefix (*pkg, "http://") ||
|
auto pkg = *pkgiter;
|
||||||
g_str_has_prefix (*pkg, "https://"))
|
if (g_str_has_prefix (pkg, "http://") ||
|
||||||
|
g_str_has_prefix (pkg, "https://"))
|
||||||
{
|
{
|
||||||
g_print ("Downloading '%s'... ", *pkg);
|
g_print ("Downloading '%s'... ", pkg);
|
||||||
glnx_autofd int fd = ror_download_to_fd (*pkg, error);
|
glnx_autofd int fd = -1;
|
||||||
if (fd < 0)
|
try {
|
||||||
{
|
fd = rpmostreecxx::download_to_fd (pkg);
|
||||||
g_print ("failed!\n");
|
} catch (std::exception& e) {
|
||||||
return FALSE;
|
g_print ("failed!\n");
|
||||||
}
|
throw;
|
||||||
|
}
|
||||||
g_print ("done!\n");
|
g_print ("done!\n");
|
||||||
|
|
||||||
int idx = g_unix_fd_list_append (fd_list, fd, error);
|
int idx = g_unix_fd_list_append (fd_list, fd, error);
|
||||||
@ -1076,12 +1079,12 @@ rpmostree_sort_pkgs_strv (const char *const* pkgs,
|
|||||||
|
|
||||||
g_variant_builder_add (&builder, "h", idx);
|
g_variant_builder_add (&builder, "h", idx);
|
||||||
}
|
}
|
||||||
else if (!g_str_has_suffix (*pkg, ".rpm"))
|
else if (!g_str_has_suffix (pkg, ".rpm"))
|
||||||
g_ptr_array_add (repo_pkgs, g_strdup (*pkg));
|
g_ptr_array_add (repo_pkgs, g_strdup (pkg));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glnx_autofd int fd = -1;
|
glnx_autofd int fd = -1;
|
||||||
if (!glnx_openat_rdonly (AT_FDCWD, *pkg, TRUE, &fd, error))
|
if (!glnx_openat_rdonly (AT_FDCWD, pkg, TRUE, &fd, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
int idx = g_unix_fd_list_append (fd_list, fd, error);
|
int idx = g_unix_fd_list_append (fd_list, fd, error);
|
||||||
|
Loading…
Reference in New Issue
Block a user