Struct DebFile

Source
pub struct DebFile { /* private fields */ }
Expand description

Used in the DebPackage struct to represent files in a package’s archives.

This struct contains the file’s contents, permissions, and it’s path in the final package.

Implementations§

Source§

impl DebFile

Source

pub fn from_path<F, T>(from: F, to: T) -> Result<Self>
where F: AsRef<Path>, T: AsRef<OsStr>,

Creates a DebFile from a path.

from is a path to a file on your system that you’re trying to add to the package. to is where the file will go once the package is installed on a user’s system.

On Unix systems, the file’s mode will automatically be set based on from. On Windows, the file’s mode will be set to 33188.

§Errors

This function will return an error if from does not exist or can’t be read.

§Example
use deb_rust::DebFile;
use deb_rust::binary::DebPackage;

let mut package = DebPackage::new("example")
    .with_file(DebFile::from_path(
        "target/release/example",
        "/usr/bin/example",
    ).unwrap());
Source

pub fn from_buf<T>(buf: Vec<u8>, to: T) -> Self
where T: AsRef<OsStr>,

Creates a DebFile from a buffer.

buf is a buffer which will be added as the file’s contents. to is where the file will go once the package is installed on a user’s system.

The file’s mode is set to 33188. Permission’s must be managed manually.

§Example
use deb_rust::DebFile;
use deb_rust::binary::DebPackage;

let mut package = DebPackage::new("example")
    .with_file(DebFile::from_buf(
        "#!/usr/bin/bash\necho Hello world!"
            .as_bytes()
            .to_vec(),
        "/usr/bin/example",
    ).is_exec());
Source

pub fn is_exec(self) -> Self

Sets the file’s mode to have executable permissions.

Source

pub fn is_conf(self) -> Self

Sets the file’s mode to have read/write permissions, without executable.

Source

pub fn set_contents(self, contents: Vec<u8>) -> Self

Sets the file’s contents to contents.

Source

pub fn set_mode(self, mode: u32) -> Self

Sets the file’s mode to mode.

Source

pub fn set_path<T: AsRef<OsStr>>(self, to: T) -> Self

Sets the file’s path to to.

Source

pub fn contents(&self) -> &Vec<u8>

Returns the file’s contents.

Source

pub fn mode(&self) -> &u32

Returns the file’s mode.

Source

pub fn path(&self) -> &PathBuf

Returns the file’s path.

Trait Implementations§

Source§

impl Debug for DebFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.