#![allow(dead_code)] use std::io; use std::path::Path; use tokio::fs; pub async fn create_dir_allow_existing(path: impl AsRef) -> io::Result<()> { match fs::create_dir(path).await { Ok(_) => Ok(()), Err(e) => { if e.kind() == io::ErrorKind::AlreadyExists { Ok(()) } else { Err(e) } } } } pub async fn remove_file_allow_not_found(path: impl AsRef) -> io::Result<()> { match fs::remove_file(path).await { Ok(_) => Ok(()), Err(e) => { if e.kind() == io::ErrorKind::NotFound { Ok(()) } else { Err(e) } } } } pub async fn symlink_update_existing( src: impl AsRef, dst: impl AsRef, ) -> io::Result<()> { let src = src.as_ref(); let dst = dst.as_ref(); match fs::symlink(&src, &dst).await { Ok(_) => Ok(()), Err(e) => { if e.kind() == io::ErrorKind::AlreadyExists { let path = fs::read_link(&dst).await?; if path == src { return Ok(()); } fs::remove_file(&dst).await?; fs::symlink(&src, &dst).await } else { Err(e) } } } }