summaryrefslogtreecommitdiffstats
path: root/nix-rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'nix-rust/src')
-rw-r--r--nix-rust/src/c.rs20
-rw-r--r--nix-rust/src/foreign.rs14
-rw-r--r--nix-rust/src/lib.rs1
-rw-r--r--nix-rust/src/util/mod.rs1
-rw-r--r--nix-rust/src/util/tarfile.rs56
5 files changed, 1 insertions, 91 deletions
diff --git a/nix-rust/src/c.rs b/nix-rust/src/c.rs
index 8d2507d37..c1358545f 100644
--- a/nix-rust/src/c.rs
+++ b/nix-rust/src/c.rs
@@ -1,22 +1,4 @@
-use super::{
- error,
- foreign::{self},
- store::path,
- store::StorePath,
- util,
-};
-
-#[no_mangle]
-pub unsafe extern "C" fn unpack_tarfile(
- source: foreign::Source,
- dest_dir: &str,
- out: *mut Result<(), error::CppException>,
-) {
- out.write(
- util::tarfile::unpack_tarfile(source, std::path::Path::new(dest_dir))
- .map_err(|err| err.into()),
- );
-}
+use super::{error, store::path, store::StorePath, util};
#[no_mangle]
pub unsafe extern "C" fn ffi_String_new(s: &str, out: *mut String) {
diff --git a/nix-rust/src/foreign.rs b/nix-rust/src/foreign.rs
deleted file mode 100644
index 7bce7753c..000000000
--- a/nix-rust/src/foreign.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-/// A wrapper around Nix's Source class that provides the Read trait.
-#[repr(C)]
-pub struct Source {
- fun: extern "C" fn(this: *mut libc::c_void, data: &mut [u8]) -> usize,
- this: *mut libc::c_void,
-}
-
-impl std::io::Read for Source {
- fn read(&mut self, buf: &mut [u8]) -> std::result::Result<usize, std::io::Error> {
- let n = (self.fun)(self.this, buf);
- assert!(n <= buf.len());
- Ok(n)
- }
-}
diff --git a/nix-rust/src/lib.rs b/nix-rust/src/lib.rs
index 9935cd27a..e62613ba8 100644
--- a/nix-rust/src/lib.rs
+++ b/nix-rust/src/lib.rs
@@ -12,7 +12,6 @@ extern crate proptest;
#[cfg(not(test))]
mod c;
mod error;
-mod foreign;
#[cfg(unused)]
mod nar;
mod store;
diff --git a/nix-rust/src/util/mod.rs b/nix-rust/src/util/mod.rs
index cd852c55f..eaad9d406 100644
--- a/nix-rust/src/util/mod.rs
+++ b/nix-rust/src/util/mod.rs
@@ -1,2 +1 @@
pub mod base32;
-pub mod tarfile;
diff --git a/nix-rust/src/util/tarfile.rs b/nix-rust/src/util/tarfile.rs
deleted file mode 100644
index 74d60692c..000000000
--- a/nix-rust/src/util/tarfile.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-use crate::{foreign::Source, Error};
-use std::fs;
-use std::io;
-use std::os::unix::fs::OpenOptionsExt;
-use std::path::{Component, Path};
-use tar::Archive;
-
-pub fn unpack_tarfile(source: Source, dest_dir: &Path) -> Result<(), Error> {
- fs::create_dir_all(dest_dir)?;
-
- let mut tar = Archive::new(source);
-
- for file in tar.entries()? {
- let mut file = file?;
-
- let path = file.path()?;
-
- for i in path.components() {
- if let Component::Prefix(_) | Component::RootDir | Component::ParentDir = i {
- return Err(Error::BadTarFileMemberName(
- file.path()?.to_str().unwrap().to_string(),
- ));
- }
- }
-
- let dest_file = dest_dir.join(path);
-
- fs::create_dir_all(dest_file.parent().unwrap())?;
-
- match file.header().entry_type() {
- tar::EntryType::Directory => {
- fs::create_dir(dest_file)?;
- }
- tar::EntryType::Regular => {
- let mode = if file.header().mode()? & (libc::S_IXUSR as u32) == 0 {
- 0o666
- } else {
- 0o777
- };
- let mut f = fs::OpenOptions::new()
- .create(true)
- .write(true)
- .mode(mode)
- .open(dest_file)?;
- io::copy(&mut file, &mut f)?;
- }
- tar::EntryType::Symlink => {
- std::os::unix::fs::symlink(file.header().link_name()?.unwrap(), dest_file)?;
- }
- tar::EntryType::XGlobalHeader | tar::EntryType::XHeader => {}
- t => return Err(Error::Misc(format!("unsupported tar entry type '{:?}'", t))),
- }
- }
-
- Ok(())
-}