Implement path_filestat_get & path_filestat_set_times on Windows.

This commit is contained in:
Marcin Mielniczuk
2019-08-21 12:47:34 +02:00
committed by Jakub Konka
parent 2ed69b1d10
commit 1bf5106f40
4 changed files with 21 additions and 5 deletions

View File

@@ -136,7 +136,6 @@ cfg_if::cfg_if! {
"symlink_loop" => true,
"clock_time_get" => true,
"truncation_rights" => true,
"path_filestat" => true,
_ => false,
}
} else {

View File

@@ -9,6 +9,7 @@ use crate::sys::{errno_from_ioerror, host_impl, hostcalls_impl};
use crate::{host, wasm32, Result};
use filetime::{set_file_handle_times, FileTime};
use log::trace;
use std::fs::File;
use std::io::{self, Read, Seek, SeekFrom, Write};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
@@ -766,6 +767,15 @@ pub(crate) fn fd_filestat_set_times(
let st_mtim = dec_timestamp(st_mtim);
let fst_flags = dec_fstflags(fst_flags);
fd_filestat_set_times_impl(fd, st_atim, st_mtim, fst_flags)
}
pub(crate) fn fd_filestat_set_times_impl(
fd: &File,
st_atim: wasm32::__wasi_timestamp_t,
st_mtim: wasm32::__wasi_timestamp_t,
fst_flags: wasm32::__wasi_fstflags_t,
) -> Result<()> {
let set_atim = fst_flags & host::__WASI_FILESTAT_SET_ATIM != 0;
let set_atim_now = fst_flags & host::__WASI_FILESTAT_SET_ATIM_NOW != 0;
let set_mtim = fst_flags & host::__WASI_FILESTAT_SET_MTIM != 0;

View File

@@ -4,7 +4,7 @@ use super::fs_helpers::*;
use crate::ctx::WasiCtx;
use crate::fdentry::FdEntry;
use crate::helpers::systemtime_to_timestamp;
use crate::hostcalls_impl::PathGet;
use crate::hostcalls_impl::{fd_filestat_set_times_impl, PathGet};
use crate::sys::fdentry_impl::determine_type_rights;
use crate::sys::host_impl;
use crate::sys::hostcalls_impl::fs_helpers::PathGetExt;
@@ -311,7 +311,9 @@ pub(crate) fn path_filestat_get(
resolved: PathGet,
dirflags: host::__wasi_lookupflags_t,
) -> Result<host::__wasi_filestat_t> {
unimplemented!("path_filestat_get")
let path = resolved.concatenate()?;
let file = File::open(path).map_err(errno_from_ioerror)?;
fd_filestat_get_impl(&file)
}
pub(crate) fn path_filestat_set_times(
@@ -321,7 +323,13 @@ pub(crate) fn path_filestat_set_times(
mut st_mtim: host::__wasi_timestamp_t,
fst_flags: host::__wasi_fstflags_t,
) -> Result<()> {
unimplemented!("path_filestat_set_times")
use winx::file::AccessMode;
let path = resolved.concatenate()?;
let file = OpenOptions::new()
.access_mode(AccessMode::FILE_WRITE_ATTRIBUTES.bits())
.open(path)
.map_err(errno_from_ioerror)?;
fd_filestat_set_times_impl(&file, st_atim, st_mtim, fst_flags)
}
pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> Result<()> {

View File

@@ -1505,5 +1505,4 @@ mod test {
)
);
}
}