diff options
Diffstat (limited to 'ext/fs')
-rw-r--r-- | ext/fs/30_fs.js | 4 | ||||
-rw-r--r-- | ext/fs/in_memory_fs.rs | 21 | ||||
-rw-r--r-- | ext/fs/interface.rs | 17 | ||||
-rw-r--r-- | ext/fs/std_fs.rs | 48 |
4 files changed, 85 insertions, 5 deletions
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 183e51e50..767ed11f4 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -473,8 +473,8 @@ function toUnixTimeFromEpoch(value) { ]; } - const seconds = value; - const nanoseconds = 0; + const seconds = MathTrunc(value); + const nanoseconds = MathTrunc((value * 1e3) - (seconds * 1e3)) * 1e6; return [ seconds, diff --git a/ext/fs/in_memory_fs.rs b/ext/fs/in_memory_fs.rs index 153327ff6..e2babf40a 100644 --- a/ext/fs/in_memory_fs.rs +++ b/ext/fs/in_memory_fs.rs @@ -350,6 +350,27 @@ impl FileSystem for InMemoryFs { self.utime_sync(&path, atime_secs, atime_nanos, mtime_secs, mtime_nanos) } + fn lutime_sync( + &self, + _path: &Path, + _atime_secs: i64, + _atime_nanos: u32, + _mtime_secs: i64, + _mtime_nanos: u32, + ) -> FsResult<()> { + Err(FsError::NotSupported) + } + async fn lutime_async( + &self, + path: PathBuf, + atime_secs: i64, + atime_nanos: u32, + mtime_secs: i64, + mtime_nanos: u32, + ) -> FsResult<()> { + self.lutime_sync(&path, atime_secs, atime_nanos, mtime_secs, mtime_nanos) + } + fn write_file_sync( &self, path: &Path, diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 6e3c359bb..6036f8228 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -221,6 +221,23 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync { mtime_nanos: u32, ) -> FsResult<()>; + fn lutime_sync( + &self, + path: &Path, + atime_secs: i64, + atime_nanos: u32, + mtime_secs: i64, + mtime_nanos: u32, + ) -> FsResult<()>; + async fn lutime_async( + &self, + path: PathBuf, + atime_secs: i64, + atime_nanos: u32, + mtime_secs: i64, + mtime_nanos: u32, + ) -> FsResult<()>; + fn write_file_sync( &self, path: &Path, diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index 054f5c9c4..79f66cc4b 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -274,6 +274,35 @@ impl FileSystem for RealFs { .await? } + fn lutime_sync( + &self, + path: &Path, + atime_secs: i64, + atime_nanos: u32, + mtime_secs: i64, + mtime_nanos: u32, + ) -> FsResult<()> { + let atime = filetime::FileTime::from_unix_time(atime_secs, atime_nanos); + let mtime = filetime::FileTime::from_unix_time(mtime_secs, mtime_nanos); + filetime::set_symlink_file_times(path, atime, mtime).map_err(Into::into) + } + + async fn lutime_async( + &self, + path: PathBuf, + atime_secs: i64, + atime_nanos: u32, + mtime_secs: i64, + mtime_nanos: u32, + ) -> FsResult<()> { + let atime = filetime::FileTime::from_unix_time(atime_secs, atime_nanos); + let mtime = filetime::FileTime::from_unix_time(mtime_secs, mtime_nanos); + spawn_blocking(move || { + filetime::set_symlink_file_times(path, atime, mtime).map_err(Into::into) + }) + .await? + } + fn write_file_sync( &self, path: &Path, @@ -927,9 +956,14 @@ fn open_with_access_check( }; (*access_check)(true, &path, &options)?; - // For windows - #[allow(unused_mut)] let mut opts: fs::OpenOptions = open_options(options); + #[cfg(windows)] + { + // allow opening directories + use std::os::windows::fs::OpenOptionsExt; + opts.custom_flags(winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS); + } + #[cfg(unix)] { // Don't follow symlinks on open -- we must always pass fully-resolved files @@ -943,7 +977,15 @@ fn open_with_access_check( Ok(opts.open(&path)?) } else { - let opts = open_options(options); + // for unix + #[allow(unused_mut)] + let mut opts = open_options(options); + #[cfg(windows)] + { + // allow opening directories + use std::os::windows::fs::OpenOptionsExt; + opts.custom_flags(winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS); + } Ok(opts.open(path)?) } } |