Fields§
§version: String
The current version of the installation.
ignore: Vec<String>
Files to ignore when generating a package.
Implementations§
source§impl Metadata
impl Metadata
sourcepub fn from_dir<P: AsRef<Path>>(directory: P) -> Result<Self, Error>
pub fn from_dir<P: AsRef<Path>>(directory: P) -> Result<Self, Error>
Examples found in repository?
src/package/mod.rs (line 112)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
pub fn apply_to_directory(package_path: &Path, directory_path: &Path) -> Result<(), Error> {
// Check the directory is an eto directory and load its metadata
let metadata =
Metadata::from_dir(directory_path).context("directory is not an eto tracked directory")?;
// Open the package
let mut file = open_package_file(package_path)?;
// Load the manifest from the package
let manifest = read_manifest(&mut file)?;
// Verify current version matches the manifest old version
if manifest.diff.old_version != metadata.version {
bail!(
"package was made for version \"{}\", but current version is \"{}\"",
manifest.diff.old_version,
metadata.version
);
}
// Apply changes from the manifest
read_unpack_files(&mut file, directory_path).context("failed to decode gzip data block")?;
for delete in &manifest.diff.delete {
event!(Level::INFO, path = delete.display().to_string(), "delete");
let mut target = directory_path.to_owned();
target.push(delete);
let result = std::fs::remove_file(target);
// We don't particularly care if this doesn't succeed, but if it doesn't at least log it
if result.is_err() {
event!(Level::WARN, "attempted to remove file that doesn't exist");
}
}
Ok(())
}
More examples
src/state.rs (line 31)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
pub fn read_dir(directory: &Path) -> Result<Self, Error> {
event!(
Level::INFO,
directory = directory.display().to_string(),
"reading state"
);
let mut files = HashMap::new();
// Read state metadata
let metadata = Metadata::from_dir(directory)?;
event!(Level::INFO, version = metadata.version, "metadata");
// Compile ignore patterns
let ignores: Result<Vec<_>, _> = metadata
.ignore
.into_iter()
.map(|ignore| Pattern::new(&ignore))
.collect();
let mut ignores = ignores?;
// Always ignore eto.log
ignores.push(Pattern::new("eto.log").unwrap());
// Read all state files (this includes the metadata file intentionally)
'outer: for entry in WalkDir::new(directory) {
let entry = entry?;
let path = entry.path();
// We don't handle directories directly, just files
if entry.path().is_dir() {
continue;
}
let path_str = path.display().to_string();
event!(Level::DEBUG, path = path_str, "checking path");
// Check if we need to ignore this
let diff_path = diff_paths(path, directory).unwrap();
for ignore in &ignores {
if ignore.matches_path(&diff_path) {
event!(Level::DEBUG, path = path_str, "ignoring");
continue 'outer;
}
}
// We've found a file, hash it so we can track changes
let bytes = std::fs::read(path).context("failed to read file to track")?;
let hash = sha256::digest(bytes.as_slice());
event!(
Level::DEBUG,
path = diff_path.display().to_string(),
hash,
"adding"
);
files.insert(diff_path, hash);
}
Ok(Self {
version: metadata.version,
files,
})
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for Metadata
impl<'de> Deserialize<'de> for Metadata
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more