async fn init_op(
        &mut self,
        mode: Mode,
        path: impl AsRef<std::path::Path>,
    ) -> Result<(), Error> {
        if mode.is_write() {
            // https://github.com/sfackler/shell-escape/issues/5
            let path = path.as_ref().to_string_lossy();

            // for writes, we want a stronger (and cheaper) test than can()
            // we can't actually use `touch`, since it also works for dirs
            // note that this works b/c stdin is Stdio::null()
            let touch = self
                .session
                .command("cat")
                .raw_arg(">>")
                .arg(&path)
                .stdin(Stdio::null())
                .output()
                .await?;
            if touch.status.success() {
                return Ok(());
            }

            // let's find out _why_ it failed
            let stderr = String::from_utf8_lossy(&touch.stderr);
            if stderr.contains("No such file or directory") {
                Err(Error::Remote(io::Error::new(
                    io::ErrorKind::NotFound,
                    &*stderr,
                )))
            } else {
                Err(Error::Remote(io::Error::new(
                    io::ErrorKind::PermissionDenied,
                    &*stderr,
                )))
            }
        } else {
            self.can(Mode::Read, path).await
        }
    }
/// Initialize the given operation on the target file.
///
/// Note that this function is not guaranteed to be side-effect free for writes. Specifically,
/// it will create the target file in order to test whether it is writeable.
Initialize the given operation on the target file.
Note that this function is not guaranteed to be side-effect free for writes. Specifically,
it will create the target file in order to test whether it is writeable.
Initialize the given operation on the target file . Note that this function is not guaranteed to be side - effect free for writes . Specifically it will create the target file in order to test whether it is writeable .
async fn init_op(
        &mut self,
        mode: Mode,
        path: impl AsRef<std::path::Path>,
    ) -> Result<(), Error> {
        if mode.is_write() {
            // https://github.com/sfackler/shell-escape/issues/5
            let path = path.as_ref().to_string_lossy();
            // for writes, we want a stronger (and cheaper) test than can()
            // we can't actually use `touch`, since it also works for dirs
            // note that this works b/c stdin is Stdio::null()
            let touch = self
                .session
                .command("cat")
                .raw_arg(">>")
                .arg(&path)
                .stdin(Stdio::null())
                .output()
                .await?;
            if touch.status.success() {
                return Ok(());
            }
            // let's find out _why_ it failed
            let stderr = String::from_utf8_lossy(&touch.stderr);
            if stderr.contains("No such file or directory") {
                Err(Error::Remote(io::Error::new(
                    io::ErrorKind::NotFound,
                    &*stderr,
                )))
            } else {
                Err(Error::Remote(io::Error::new(
                    io::ErrorKind::PermissionDenied,
                    &*stderr,
                )))
            }
        } else {
            self.can(Mode::Read, path).await
        }
    }
async fn init_op ( & mut self , mode : Mode , path : impl AsRef < std :: path :: Path > , ) -> Result < ( ) , Error > { if mode . is_write ( ) { // https://github.com/sfackler/shell-escape/issues/5 let path = path . as_ref ( ) . to_string_lossy ( ) ; // for writes, we want a stronger (and cheaper) test than can() // we can't actually use `touch`, since it also works for dirs // note that this works b/c stdin is Stdio::null() let touch = self . session . command ( " " ) . raw_arg ( " " ) . arg ( & path ) . stdin ( Stdio :: null ( ) ) . output ( ) . await ? ; if touch . status . success ( ) { return Ok ( ( ) ) ; } // let's find out _why_ it failed let stderr = String :: from_utf8_lossy ( & touch . stderr ) ; if stderr . contains ( " " ) { Err ( Error :: Remote ( io :: Error :: new ( io :: ErrorKind :: NotFound , & * stderr , ) ) ) } else { Err ( Error :: Remote ( io :: Error :: new ( io :: ErrorKind :: PermissionDenied , & * stderr , ) ) ) } } else { self . can ( Mode :: Read , path ) . await } }
Initialize the given operation on the target file.
Initialize the given operation on the target file .
&mut self
mode
Mode
path
impl AsRef<std::path::Path>
&mut self
mode
Mode
path
impl AsRef<std::path::Path>