// Attempts to create a new file at the given |relative_path|.
// Replaces the file contents if it already exists.
Attempts to create a new file at the given |relative_path|.
Replaces the file contents if it already exists.
Attempts to create a new file at the given |relative_path| . Replaces the file contents if it already exists .
pub async fn create_file<P: AsRef<Path>>(&self, relative_path: P, data: &[u8]) -> Result<()> {
        let path = self.path.join(relative_path.as_ref());
        let relative_path = match relative_path.as_ref().to_str() {
            Some(relative_path) => relative_path,
            None => return Err(format_err!("Relative path is not valid unicode")),
        };
        let file = match open_file_no_describe(
            &self.proxy,
            relative_path,
            fio::OPEN_RIGHT_WRITABLE | fio::OPEN_FLAG_CREATE,
        ) {
            Ok(proxy) => proxy,
            Err(e) => {
                return Err(format_err!(
                    "Could not open file `{}`: {}",
                    path.as_path().display(),
                    e
                ))
            }
        };
        match file.truncate(0).await {
            Ok(s) => {
                Status::ok(s).map_err(|e| {
                    format_err!("Could not truncate file `{}`: {}", path.as_path().display(), &e)
                })?;
            }
            Err(e) => {
                return Err(format_err!(
                    "Could not truncate file `{}`: {}",
                    path.as_path().display(),
                    &e
                ))
            }
        }
        match write(&file, data).await {
            Ok(()) => {}
            Err(e) => {
                return Err(format_err!(
                    "Could not write to file `{}`: {}",
                    path.as_path().display(),
                    e
                ))
            }
        }
        match close(file).await {
            Ok(()) => Ok(()),
            Err(e) => {
                Err(format_err!("Could not close file `{}`: {}", path.as_path().display(), e))
            }
        }
    }
pub async fn create_file < P : AsRef < Path > > ( & self , relative_path : P , data : & [ u8 ] ) -> Result < ( ) > { let path = self . path . join ( relative_path . as_ref ( ) ) ; let relative_path = match relative_path . as_ref ( ) . to_str ( ) { Some ( relative_path ) => relative_path , None => return Err ( format_err ! ( " " ) ) , } ; let file = match open_file_no_describe ( & self . proxy , relative_path , fio :: OPEN_RIGHT_WRITABLE | fio :: OPEN_FLAG_CREATE , ) { Ok ( proxy ) => proxy , Err ( e ) => { return Err ( format_err ! ( " " path as_path ( ) display ( ) e ) ) } } ; match file . truncate ( 0 ) . await { Ok ( s ) => { Status :: ok ( s ) . map_err ( | e | { format_err ! ( " " path as_path ( ) display ( ) e ) } ) ? ; } Err ( e ) => { return Err ( format_err ! ( " " path as_path ( ) display ( ) e ) ) } } match write ( & file , data ) . await { Ok ( ( ) ) => { } Err ( e ) => { return Err ( format_err ! ( " " path as_path ( ) display ( ) e ) ) } } match close ( file ) . await { Ok ( ( ) ) => Ok ( ( ) ) , Err ( e ) => { Err ( format_err ! ( " " path as_path ( ) display ( ) e ) ) } } }
Attempts to create a new file at the given |relative_path|.
Attempts to create a new file at the given |relative_path| .
&self
relative_path
P
data
&[u8]