Revert "Fully switch to File::set_times() from utime crate (#3501)" (#3502)

This reverts commit 723b5e9bcc.
This commit is contained in:
Damien Elmes 2024-10-16 00:35:26 +10:00 committed by GitHub
parent 723b5e9bcc
commit f3ca4646fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 32 additions and 8 deletions

11
Cargo.lock generated
View file

@ -171,6 +171,7 @@ dependencies = [
"unic-ucd-category", "unic-ucd-category",
"unicase", "unicase",
"unicode-normalization", "unicode-normalization",
"utime",
"windows 0.56.0", "windows 0.56.0",
"wiremock", "wiremock",
"zip", "zip",
@ -6421,6 +6422,16 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "utime"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91baa0c65eabd12fcbdac8cc35ff16159cab95cae96d0222d6d0271db6193cef"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.10.0" version = "1.10.0"

View file

@ -52,6 +52,7 @@ ninja_gen = { "path" = "build/ninja_gen" }
# pinned # pinned
unicase = "=2.6.0" # any changes could invalidate sqlite indexes unicase = "=2.6.0" # any changes could invalidate sqlite indexes
utime = "=0.3.1" # marked as deprecated, but no native solution for folder mtimes exists
# normal # normal
ammonia = "4.0.0" ammonia = "4.0.0"

View file

@ -4238,6 +4238,15 @@
"license_file": null, "license_file": null,
"description": "Incremental, zero-copy UTF-8 decoding with error handling" "description": "Incremental, zero-copy UTF-8 decoding with error handling"
}, },
{
"name": "utime",
"version": "0.3.1",
"authors": "Hyeon Kim <simnalamburt@gmail.com>",
"repository": "https://github.com/simnalamburt/utime",
"license": "Apache-2.0 OR MIT",
"license_file": null,
"description": "A missing utime function for Rust."
},
{ {
"name": "uuid", "name": "uuid",
"version": "1.10.0", "version": "1.10.0",

View file

@ -103,6 +103,7 @@ tracing-subscriber.workspace = true
unic-ucd-category.workspace = true unic-ucd-category.workspace = true
unicase.workspace = true unicase.workspace = true
unicode-normalization.workspace = true unicode-normalization.workspace = true
utime.workspace = true
zip.workspace = true zip.workspace = true
zstd.workspace = true zstd.workspace = true

View file

@ -53,9 +53,10 @@ pub fn write_file(path: impl AsRef<Path>, contents: impl AsRef<[u8]>) -> Result<
op: FileOp::Write, op: FileOp::Write,
}) })
} }
/// See [File::set_times]. /// See [File::set_times]. Note that this won't work on folders.
pub fn set_file_times(path: impl AsRef<Path>, times: FileTimes) -> Result<()> { pub fn set_file_times(path: impl AsRef<Path>, times: FileTimes) -> Result<()> {
open_file(&path)?.set_times(times).context(FileIoSnafu { let file = open_file_ext(&path, OpenOptions::new().write(true).to_owned())?;
file.set_times(times).context(FileIoSnafu {
path: path.as_ref(), path: path.as_ref(),
op: FileOp::SetFileTimes, op: FileOp::SetFileTimes,
}) })

View file

@ -239,13 +239,11 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::fs; use std::fs;
use std::fs::FileTimes;
use std::path::Path; use std::path::Path;
use std::time; use std::time;
use std::time::Duration; use std::time::Duration;
use anki_io::create_dir; use anki_io::create_dir;
use anki_io::set_file_times;
use anki_io::write_file; use anki_io::write_file;
use tempfile::tempdir; use tempfile::tempdir;
@ -259,10 +257,13 @@ mod test {
fn change_mtime(p: &Path) { fn change_mtime(p: &Path) {
let mtime = p.metadata().unwrap().modified().unwrap(); let mtime = p.metadata().unwrap().modified().unwrap();
let new_mtime = mtime - Duration::from_secs(3); let new_mtime = mtime - Duration::from_secs(3);
let times = FileTimes::new() let secs = new_mtime
.set_accessed(new_mtime) .duration_since(time::UNIX_EPOCH)
.set_modified(new_mtime); .unwrap()
set_file_times(p, times).unwrap(); .as_secs() as i64;
// we rely on an external crate, as Rust's File::set_times() does not work
// on directories
utime::set_file_times(p, secs, secs).unwrap();
} }
#[test] #[test]