mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
[red-knot] Use web-time instead of FileTime::now (#16967)
## Summary `std::time::now` isn't available on `wasm32-unknown-unknown` but it is used by `FileTime::now`. This PR replaces the usages of `FileTime::now` with a target specific helper function that we already had in the memory file system. Fixes https://github.com/astral-sh/ruff/issues/16966 ## Test Plan Tested that the playground no longer crash when adding an extra-path
This commit is contained in:
parent
4975c2f027
commit
8d16a5c8c9
4 changed files with 38 additions and 36 deletions
|
|
@ -7,6 +7,7 @@ pub use os::testing::UserConfigDirectoryOverrideGuard;
|
|||
#[cfg(feature = "os")]
|
||||
pub use os::OsSystem;
|
||||
|
||||
use filetime::FileTime;
|
||||
use ruff_notebook::{Notebook, NotebookError};
|
||||
use std::error::Error;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
|
@ -346,3 +347,27 @@ pub enum GlobErrorKind {
|
|||
IOError(io::Error),
|
||||
NonUtf8Path,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn file_time_now() -> FileTime {
|
||||
FileTime::now()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn file_time_now() -> FileTime {
|
||||
// Copied from FileTime::from_system_time()
|
||||
let time = web_time::SystemTime::now();
|
||||
|
||||
time.duration_since(web_time::UNIX_EPOCH)
|
||||
.map(|d| FileTime::from_unix_time(d.as_secs() as i64, d.subsec_nanos()))
|
||||
.unwrap_or_else(|e| {
|
||||
let until_epoch = e.duration();
|
||||
let (sec_offset, nanos) = if until_epoch.subsec_nanos() == 0 {
|
||||
(0, 0)
|
||||
} else {
|
||||
(-1, 1_000_000_000 - until_epoch.subsec_nanos())
|
||||
};
|
||||
|
||||
FileTime::from_unix_time(-(until_epoch.as_secs() as i64) + sec_offset, nanos)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue