Tidy up file config init
This commit is contained in:
@@ -41,10 +41,42 @@ pub struct FileConfig {
|
||||
pub gid: Option<u32>,
|
||||
#[serde(default)]
|
||||
pub recursive_chown: bool,
|
||||
#[serde(default)]
|
||||
pub postinstall: bool,
|
||||
}
|
||||
|
||||
// TODO: Rewrite impls
|
||||
impl FileConfig {
|
||||
pub fn new_file(path: String, data: String) -> FileConfig {
|
||||
FileConfig {
|
||||
path,
|
||||
data,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_directory(path: String) -> FileConfig {
|
||||
FileConfig {
|
||||
path,
|
||||
data: String::new(),
|
||||
directory: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_mod(&mut self, mode: u32, uid: u32, gid: u32) -> &mut FileConfig {
|
||||
self.mode = Some(mode);
|
||||
self.uid = Some(uid);
|
||||
self.gid = Some(gid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_recursive_mod(&mut self, mode: u32, uid: u32, gid: u32) -> &mut FileConfig {
|
||||
self.with_mod(mode, uid, gid);
|
||||
self.recursive_chown = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn create<P: AsRef<Path>>(&self, prefix: P) -> Result<()> {
|
||||
let path = self.path.trim_start_matches('/');
|
||||
let target_file = prefix.as_ref().join(path);
|
||||
|
||||
Reference in New Issue
Block a user