~kmaasrud/m2dir-rs

c0eef072c4c3ae096309003a96d91c1eca9577ac — Knut Magnus Aasrud 2 months ago 4f63b62
feat: add remove_flag function
1 files changed, 26 insertions(+), 3 deletions(-)

M src/entry.rs
M src/entry.rs => src/entry.rs +26 -3
@@ 76,10 76,33 @@ impl Entry {
    ///
    /// Returns an [`std::io::Error`] if there is an issue updating the flags on
    /// disk.
    pub fn set_flag(&self, flag: String) -> io::Result<()> {
    pub fn add_flag(&self, flag: String) -> io::Result<()> {
        let mut metadata = self.metadata();
        metadata.flags.insert(flag);
        self.set_metadata(metadata)
        if metadata.flags.insert(flag) {
            self.set_metadata(metadata)?;
        }
        Ok(())
    }

    /// Removes a flag to the metadata of this m2dir and writes the update to
    /// disk.
    ///
    /// This function modifies the current set of flags by removing the flag
    /// from the metadata and then persisting the updated set to the filesystem.
    /// If writing many flags, it is more efficient to modify the metadata
    /// structure directly first and then use [`Entry::set_metadata`] to write
    /// all changes in one operation.
    ///
    /// # Errors
    ///
    /// Returns an [`std::io::Error`] if there is an issue updating the flags on
    /// disk.
    pub fn remove_flag<S: AsRef<str>>(&self, flag: S) -> io::Result<()> {
        let mut metadata = self.metadata();
        if metadata.flags.remove(flag.as_ref()) {
            self.set_metadata(metadata)?;
        }
        Ok(())
    }

    /// Deletes the email message file and its associated metadata files.