alnyan/yggdrasil: implement fs::copy() + OpenOptionsExt
This commit is contained in:
parent
9a21c79df2
commit
034343146e
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use yggdrasil_rt::io::FileMode;
|
use yggdrasil_rt::io::FileMode;
|
||||||
|
|
||||||
use crate::fs::Metadata;
|
use crate::fs::{Metadata, OpenOptions};
|
||||||
use crate::sys_common::AsInner;
|
use crate::sys_common::{AsInner, AsInnerMut};
|
||||||
|
|
||||||
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||||
pub trait MetadataExt {
|
pub trait MetadataExt {
|
||||||
@ -13,6 +13,11 @@ pub trait MetadataExt {
|
|||||||
fn block_size(&self) -> u64;
|
fn block_size(&self) -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "yggdrasil_os", issue = "none")]
|
||||||
|
pub trait OpenOptionsExt {
|
||||||
|
fn mode_ext(&mut self, mode: FileMode) -> &mut Self;
|
||||||
|
}
|
||||||
|
|
||||||
impl MetadataExt for Metadata {
|
impl MetadataExt for Metadata {
|
||||||
fn mode_ext(&self) -> FileMode {
|
fn mode_ext(&self) -> FileMode {
|
||||||
self.as_inner().mode_ext()
|
self.as_inner().mode_ext()
|
||||||
@ -30,3 +35,10 @@ impl MetadataExt for Metadata {
|
|||||||
self.as_inner().block_size()
|
self.as_inner().block_size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl OpenOptionsExt for OpenOptions {
|
||||||
|
fn mode_ext(&mut self, mode: FileMode) -> &mut Self {
|
||||||
|
self.as_inner_mut().mode = mode;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,8 +18,8 @@ pub struct File(FileDesc);
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct OpenOptions {
|
pub struct OpenOptions {
|
||||||
options: OsOpenOptions,
|
pub(crate) options: OsOpenOptions,
|
||||||
mode: OsFileMode,
|
pub(crate) mode: OsFileMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenOptions {
|
impl OpenOptions {
|
||||||
|
@ -5,6 +5,7 @@ use yggdrasil_rt::io::{
|
|||||||
use yggdrasil_rt::time::SystemTime as RtSystemTime;
|
use yggdrasil_rt::time::SystemTime as RtSystemTime;
|
||||||
|
|
||||||
use crate::hash::Hash;
|
use crate::hash::Hash;
|
||||||
|
use crate::os::yggdrasil::fs::{MetadataExt, OpenOptionsExt};
|
||||||
use crate::path::{Path, PathBuf};
|
use crate::path::{Path, PathBuf};
|
||||||
use crate::sys::time::SystemTime;
|
use crate::sys::time::SystemTime;
|
||||||
use crate::sys::{cvt_io, run_with_path_str};
|
use crate::sys::{cvt_io, run_with_path_str};
|
||||||
@ -195,8 +196,18 @@ pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy(_from: &Path, _to: &Path) -> io::Result<u64> {
|
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
||||||
todo!()
|
let src_stat = from.metadata()?;
|
||||||
|
let raw_mode = src_stat.mode_ext();
|
||||||
|
let mut src = crate::fs::File::open(from)?;
|
||||||
|
let mut dst = crate::fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.create(true)
|
||||||
|
.mode_ext(raw_mode)
|
||||||
|
.open(to)?;
|
||||||
|
|
||||||
|
crate::io::copy(&mut src, &mut dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_exists(_path: &Path) -> io::Result<bool> {
|
pub fn try_exists(_path: &Path) -> io::Result<bool> {
|
||||||
|
@ -79,6 +79,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
|||||||
Ok(OsError::WouldBlock) => ErrorKind::WouldBlock,
|
Ok(OsError::WouldBlock) => ErrorKind::WouldBlock,
|
||||||
Ok(OsError::ReadOnly) => ErrorKind::ReadOnlyFilesystem,
|
Ok(OsError::ReadOnly) => ErrorKind::ReadOnlyFilesystem,
|
||||||
Ok(OsError::PermissionDenied) => ErrorKind::PermissionDenied,
|
Ok(OsError::PermissionDenied) => ErrorKind::PermissionDenied,
|
||||||
|
Ok(OsError::CrossDeviceLink) => ErrorKind::CrossesDevices,
|
||||||
Ok(OsError::UnrecognizedExecutable)
|
Ok(OsError::UnrecognizedExecutable)
|
||||||
| Ok(OsError::MissingData)
|
| Ok(OsError::MissingData)
|
||||||
| Ok(OsError::BufferTooSmall)
|
| Ok(OsError::BufferTooSmall)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user