Skip to content

Commit

Permalink
Merge pull request #18 from isbm/isbm-lockfile-on-complete
Browse files Browse the repository at this point in the history
Add a lockfile to a tinted container
  • Loading branch information
isbm authored Nov 6, 2023
2 parents 4189930 + 46b16f4 commit cce25ce
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/procdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use bytesize::ByteSize;
use filesize::PathExt;
use std::fs::{self, canonicalize, remove_file, DirEntry};
use std::fs::{self, canonicalize, remove_file, DirEntry, File};
use std::{
collections::HashSet,
io::Error,
Expand All @@ -29,11 +29,18 @@ pub struct TintProcessor {
root: PathBuf,
dry_run: bool,
autodeps: Autodeps,
lockfile: PathBuf,
}

impl TintProcessor {
pub fn new(root: PathBuf) -> Self {
TintProcessor { profile: Profile::default(), root, dry_run: true, autodeps: Autodeps::Free }
TintProcessor {
profile: Profile::default(),
root,
dry_run: true,
autodeps: Autodeps::Free,
lockfile: PathBuf::from("/.tinted.lock"),
}
}

/// Set configuration from a profile
Expand Down Expand Up @@ -115,6 +122,7 @@ impl TintProcessor {
}

TintProcessor::remove_empty_dirs(&PathBuf::from("/"))?;
File::create(&self.lockfile)?; // Create an empty lock file, indicated mission complete.

Ok(())
}
Expand Down Expand Up @@ -155,6 +163,10 @@ impl TintProcessor {
pub fn start(&self) -> Result<(), Error> {
self.switch_root()?;

if self.lockfile.exists() {
return Err(Error::new(std::io::ErrorKind::AlreadyExists, "This container seems already tinted."));
}

// Paths to keep
let mut paths: HashSet<PathBuf> = HashSet::default();

Expand Down

0 comments on commit cce25ce

Please sign in to comment.