Struct eto::Metadata

source ·
pub struct Metadata {
    pub version: String,
    pub ignore: Vec<String>,
}

Fields§

§version: String

The current version of the installation.

§ignore: Vec<String>

Files to ignore when generating a package.

Implementations§

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
Hide additional 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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more