Download codex-rs/exec-server/src/no_follow/mod.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/exec-server/src/no_follow/mod.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/exec-server/src/no_follow/mod.rs
-
curl -L -o mod.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/exec-server/src/no_follow/mod.rs
1.7 kB
| use crate::FileMetadata; | |
| use std::io; | |
| use std::path::Path; | |
| use std::time::SystemTime; | |
| use std::time::UNIX_EPOCH; | |
| mod unix; | |
| mod windows; | |
| use unix as imp; | |
| use windows as imp; | |
| pub(crate) async fn open_file(path: &Path) -> io::Result<tokio::fs::File> { | |
| imp::open_file(path.to_path_buf()).await | |
| } | |
| pub(crate) async fn write_file(path: &Path, contents: Vec<u8>) -> io::Result<()> { | |
| imp::write_file(path.to_path_buf(), contents).await | |
| } | |
| pub(crate) async fn metadata(path: &Path) -> io::Result<FileMetadata> { | |
| imp::metadata(path.to_path_buf()).await | |
| } | |
| pub(crate) async fn metadata(path: &Path) -> io::Result<FileMetadata> { | |
| imp::metadata(path.to_path_buf()) | |
| .await | |
| .map(|metadata| FileMetadata { | |
| is_directory: metadata.is_dir(), | |
| is_file: metadata.is_file(), | |
| is_symlink: false, | |
| size: metadata.len(), | |
| created_at_ms: metadata.created().ok().map_or(0, system_time_to_unix_ms), | |
| modified_at_ms: metadata.modified().ok().map_or(0, system_time_to_unix_ms), | |
| }) | |
| } | |
| fn system_time_to_unix_ms(time: SystemTime) -> i64 { | |
| time.duration_since(UNIX_EPOCH) | |
| .ok() | |
| .and_then(|duration| i64::try_from(duration.as_millis()).ok()) | |
| .unwrap_or(0) | |
| } | |
| pub(crate) async fn create_directory(path: &Path, recursive: bool) -> io::Result<()> { | |
| imp::create_directory(path.to_path_buf(), recursive).await | |
| } | |
| pub(crate) async fn remove(path: &Path, recursive: bool, force: bool) -> io::Result<()> { | |
| imp::remove(path.to_path_buf(), recursive, force).await | |
| } | |