pub fn write(&self) -> Result<()> {
        // switch users
        let _guard = switch_user(&self.user)?;

        // get our staging directory
        let stage_dir = self.stage_dir();
        truncate_dir(&stage_dir).chain_err(|| {
            format!(
                "failed to create staging directory '{}'",
                stage_dir.display()
            )
        })?;

        // write all the keys to the staging directory
        for keyset in self.keys.values() {
            let keyfilename = stage_dir.join(&keyset.filename);
            let mut keyfile = File::create(&keyfilename)
                .chain_err(|| format!("failed to create file '{:?}'", keyfilename))?;
            // if the keyset is disabled, skip it. we still want to have a
            // zero-sized file with it's name though to signal that it's
            // disabled.
            if keyset.disabled {
                continue;
            }
            for key in &keyset.keys {
                match *key {
                    AuthorizedKeyEntry::Valid { ref key } => writeln!(keyfile, "{}", key)
                        .chain_err(|| format!("failed to write to file '{:?}'", keyfilename))?,
                    AuthorizedKeyEntry::Invalid { ref key } => writeln!(keyfile, "{}", key)
                        .chain_err(|| format!("failed to write to file '{:?}'", keyfilename))?,
                }
            }

            keyfile
                .sync_all()
                .chain_err(|| format!("failed to sync file '{:?}'", keyfilename))?;
        }

        replace_dir(
            &stage_dir,
            &self.authorized_keys_dir(),
            &self.stage_old_dir(),
        )
    }
/// write writes all authorized_keys.d changes onto disk. it writes the
/// current state to a staging directory and then moves that staging
/// directory to the authorized_keys.d path.
write writes all authorized_keys.d changes onto disk. it writes the
current state to a staging directory and then moves that staging
directory to the authorized_keys.d path.
write writes all authorized_keys . d changes onto disk . it writes the current state to a staging directory and then moves that staging directory to the authorized_keys . d path .
pub fn write(&self) -> Result<()> {
        // switch users
        let _guard = switch_user(&self.user)?;
        // get our staging directory
        let stage_dir = self.stage_dir();
        truncate_dir(&stage_dir).chain_err(|| {
            format!(
                "failed to create staging directory '{}'",
                stage_dir.display()
            )
        })?;
        // write all the keys to the staging directory
        for keyset in self.keys.values() {
            let keyfilename = stage_dir.join(&keyset.filename);
            let mut keyfile = File::create(&keyfilename)
                .chain_err(|| format!("failed to create file '{:?}'", keyfilename))?;
            // if the keyset is disabled, skip it. we still want to have a
            // zero-sized file with it's name though to signal that it's
            // disabled.
            if keyset.disabled {
                continue;
            }
            for key in &keyset.keys {
                match *key {
                    AuthorizedKeyEntry::Valid { ref key } => writeln!(keyfile, "{}", key)
                        .chain_err(|| format!("failed to write to file '{:?}'", keyfilename))?,
                    AuthorizedKeyEntry::Invalid { ref key } => writeln!(keyfile, "{}", key)
                        .chain_err(|| format!("failed to write to file '{:?}'", keyfilename))?,
                }
            }
            keyfile
                .sync_all()
                .chain_err(|| format!("failed to sync file '{:?}'", keyfilename))?;
        }
        replace_dir(
            &stage_dir,
            &self.authorized_keys_dir(),
            &self.stage_old_dir(),
        )
    }
pub fn write ( & self ) -> Result < ( ) > { // switch users let _guard = switch_user ( & self . user ) ? ; // get our staging directory let stage_dir = self . stage_dir ( ) ; truncate_dir ( & stage_dir ) . chain_err ( | | { format ! ( " " stage_dir display ( ) ) } ) ? ; // write all the keys to the staging directory for keyset in self . keys . values ( ) { let keyfilename = stage_dir . join ( & keyset . filename ) ; let mut keyfile = File :: create ( & keyfilename ) . chain_err ( | | format ! ( " " keyfilename ) ) ? ; // if the keyset is disabled, skip it. we still want to have a // zero-sized file with it's name though to signal that it's // disabled. if keyset . disabled { continue ; } for key in & keyset . keys { match * key { AuthorizedKeyEntry :: Valid { ref key } => writeln ! ( keyfile " " key ) . chain_err ( | | format ! ( " " keyfilename ) ) ? , AuthorizedKeyEntry :: Invalid { ref key } => writeln ! ( keyfile " " key ) . chain_err ( | | format ! ( " " keyfilename ) ) ? , } } keyfile . sync_all ( ) . chain_err ( | | format ! ( " " keyfilename ) ) ? ; } replace_dir ( & stage_dir , & self . authorized_keys_dir ( ) , & self . stage_old_dir ( ) , ) }
write writes all authorized_keys.d changes onto disk.
write writes all authorized_keys . d changes onto disk .
&self
&self