Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
1
third-party/vendor/filetime/.cargo-checksum.json
vendored
Normal file
1
third-party/vendor/filetime/.cargo-checksum.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"files":{"Cargo.toml":"8d85b719c7034a8267e62b0d9c49995a52a25e3fcc13265dcde8229b3f3a1764","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"6cd295d9f4efe412971b1855ecaf7b19ef3956006a652ea205c456a5d33550c1","src/lib.rs":"eec6b5e3be2c1d5e068a9724b503e729a1e11dae4cd1bc816110c94a0bc14fa0","src/redox.rs":"898997b73c20818cf4601a1f4bcdf1b7dbf3b5d9d071cdc9fce5d1652f6bfc43","src/unix/android.rs":"d929826a9a92003b7aaa6435adc220efbb70c15308f9eed5ee517d88451fcaf6","src/unix/linux.rs":"648498bdf715766eeffdc2dff6a58db51cf6b244c431a6d53c33cbc73f1998d4","src/unix/macos.rs":"1b19a24bee240aba8d564405991bb0ee36ba72217461c8ac6829144d28f7e046","src/unix/mod.rs":"a34faf9cfb0bd0f18d3d99f5e5b2733fb3c8cb4ef0d948084b62a98186b3595e","src/unix/utimensat.rs":"0876aa32393689fcb5eec913c5d34954956a715913d611749b04243a2dbcf897","src/unix/utimes.rs":"d2d8ca5daed3d1ec0a0aed1fc03450deb4b7f1fcdb96ed40b8d2cfefd0e827ee","src/wasm.rs":"a82734259846a3349d42da011c1065d21f3981bd20d6eb43495e34808b83af9a","src/windows.rs":"3314a0def8028d8f2a4bc01377d5874ab9ddf8684aad13573c89b427bf2d9911"},"package":"1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd"}
|
||||
47
third-party/vendor/filetime/Cargo.toml
vendored
Normal file
47
third-party/vendor/filetime/Cargo.toml
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "filetime"
|
||||
version = "0.2.23"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
description = """
|
||||
Platform-agnostic accessors of timestamps in File metadata
|
||||
"""
|
||||
homepage = "https://github.com/alexcrichton/filetime"
|
||||
documentation = "https://docs.rs/filetime"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"timestamp",
|
||||
"mtime",
|
||||
]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/alexcrichton/filetime"
|
||||
|
||||
[dependencies.cfg-if]
|
||||
version = "1.0.0"
|
||||
|
||||
[dev-dependencies.tempfile]
|
||||
version = "3"
|
||||
|
||||
[target."cfg(target_os = \"redox\")".dependencies.redox_syscall]
|
||||
version = "0.4.1"
|
||||
|
||||
[target."cfg(unix)".dependencies.libc]
|
||||
version = "0.2.27"
|
||||
|
||||
[target."cfg(windows)".dependencies.windows-sys]
|
||||
version = "0.52.0"
|
||||
features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_Storage_FileSystem",
|
||||
]
|
||||
201
third-party/vendor/filetime/LICENSE-APACHE
vendored
Normal file
201
third-party/vendor/filetime/LICENSE-APACHE
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
25
third-party/vendor/filetime/LICENSE-MIT
vendored
Normal file
25
third-party/vendor/filetime/LICENSE-MIT
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Copyright (c) 2014 Alex Crichton
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
37
third-party/vendor/filetime/README.md
vendored
Normal file
37
third-party/vendor/filetime/README.md
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# filetime
|
||||
|
||||
[Documentation](https://docs.rs/filetime)
|
||||
|
||||
A helper library for inspecting and setting the various timestamps of files in Rust. This
|
||||
library takes into account cross-platform differences in terms of where the
|
||||
timestamps are located, what they are called, and how to convert them into a
|
||||
platform-independent representation.
|
||||
|
||||
```toml
|
||||
# Cargo.toml
|
||||
[dependencies]
|
||||
filetime = "0.2"
|
||||
```
|
||||
|
||||
# Advantages over using `std::fs::Metadata`
|
||||
|
||||
This library includes the ability to set this data, which std does not.
|
||||
|
||||
This library, when built with `RUSTFLAGS=--cfg emulate_second_only_system` set, will return all times rounded down to the second. This emulates the behavior of some file systems, mostly [HFS](https://en.wikipedia.org/wiki/HFS_Plus), allowing debugging on other hardware.
|
||||
|
||||
# License
|
||||
|
||||
This project is licensed under either of
|
||||
|
||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
||||
http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in Filetime by you, as defined in the Apache-2.0 license, shall be
|
||||
dual licensed as above, without any additional terms or conditions.
|
||||
715
third-party/vendor/filetime/src/lib.rs
vendored
Normal file
715
third-party/vendor/filetime/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,715 @@
|
|||
//! Timestamps for files in Rust
|
||||
//!
|
||||
//! This library provides platform-agnostic inspection of the various timestamps
|
||||
//! present in the standard `fs::Metadata` structure.
|
||||
//!
|
||||
//! # Installation
|
||||
//!
|
||||
//! Add this to your `Cargo.toml`:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies]
|
||||
//! filetime = "0.2"
|
||||
//! ```
|
||||
//!
|
||||
//! # Usage
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use std::fs;
|
||||
//! use filetime::FileTime;
|
||||
//!
|
||||
//! let metadata = fs::metadata("foo.txt").unwrap();
|
||||
//!
|
||||
//! let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
//! println!("{}", mtime);
|
||||
//!
|
||||
//! let atime = FileTime::from_last_access_time(&metadata);
|
||||
//! assert!(mtime < atime);
|
||||
//!
|
||||
//! // Inspect values that can be interpreted across platforms
|
||||
//! println!("{}", mtime.unix_seconds());
|
||||
//! println!("{}", mtime.nanoseconds());
|
||||
//!
|
||||
//! // Print the platform-specific value of seconds
|
||||
//! println!("{}", mtime.seconds());
|
||||
//! ```
|
||||
|
||||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "redox")] {
|
||||
#[path = "redox.rs"]
|
||||
mod imp;
|
||||
} else if #[cfg(windows)] {
|
||||
#[path = "windows.rs"]
|
||||
mod imp;
|
||||
} else if #[cfg(all(target_family = "wasm", not(target_os = "emscripten")))] {
|
||||
#[path = "wasm.rs"]
|
||||
mod imp;
|
||||
} else {
|
||||
#[path = "unix/mod.rs"]
|
||||
mod imp;
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper structure to represent a timestamp for a file.
|
||||
///
|
||||
/// The actual value contined within is platform-specific and does not have the
|
||||
/// same meaning across platforms, but comparisons and stringification can be
|
||||
/// significant among the same platform.
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Copy, Clone, Hash)]
|
||||
pub struct FileTime {
|
||||
seconds: i64,
|
||||
nanos: u32,
|
||||
}
|
||||
|
||||
impl FileTime {
|
||||
/// Creates a new timestamp representing a 0 time.
|
||||
///
|
||||
/// Useful for creating the base of a cmp::max chain of times.
|
||||
pub const fn zero() -> FileTime {
|
||||
FileTime {
|
||||
seconds: 0,
|
||||
nanos: 0,
|
||||
}
|
||||
}
|
||||
|
||||
const fn emulate_second_only_system(self) -> FileTime {
|
||||
if cfg!(emulate_second_only_system) {
|
||||
FileTime {
|
||||
seconds: self.seconds,
|
||||
nanos: 0,
|
||||
}
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new timestamp representing the current system time.
|
||||
///
|
||||
/// ```
|
||||
/// # use filetime::FileTime;
|
||||
/// #
|
||||
/// # fn example() -> std::io::Result<()> {
|
||||
/// # let path = "";
|
||||
/// #
|
||||
/// filetime::set_file_mtime(path, FileTime::now())?;
|
||||
/// #
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// Equivalent to `FileTime::from_system_time(SystemTime::now())`.
|
||||
pub fn now() -> FileTime {
|
||||
FileTime::from_system_time(SystemTime::now())
|
||||
}
|
||||
|
||||
/// Creates a new instance of `FileTime` with a number of seconds and
|
||||
/// nanoseconds relative to the Unix epoch, 1970-01-01T00:00:00Z.
|
||||
///
|
||||
/// Negative seconds represent times before the Unix epoch, and positive
|
||||
/// values represent times after it. Nanos always count forwards in time.
|
||||
///
|
||||
/// Note that this is typically the relative point that Unix time stamps are
|
||||
/// from, but on Windows the native time stamp is relative to January 1,
|
||||
/// 1601 so the return value of `seconds` from the returned `FileTime`
|
||||
/// instance may not be the same as that passed in.
|
||||
pub const fn from_unix_time(seconds: i64, nanos: u32) -> FileTime {
|
||||
FileTime {
|
||||
seconds: seconds + if cfg!(windows) { 11644473600 } else { 0 },
|
||||
nanos,
|
||||
}
|
||||
.emulate_second_only_system()
|
||||
}
|
||||
|
||||
/// Creates a new timestamp from the last modification time listed in the
|
||||
/// specified metadata.
|
||||
///
|
||||
/// The returned value corresponds to the `mtime` field of `stat` on Unix
|
||||
/// platforms and the `ftLastWriteTime` field on Windows platforms.
|
||||
pub fn from_last_modification_time(meta: &fs::Metadata) -> FileTime {
|
||||
imp::from_last_modification_time(meta).emulate_second_only_system()
|
||||
}
|
||||
|
||||
/// Creates a new timestamp from the last access time listed in the
|
||||
/// specified metadata.
|
||||
///
|
||||
/// The returned value corresponds to the `atime` field of `stat` on Unix
|
||||
/// platforms and the `ftLastAccessTime` field on Windows platforms.
|
||||
pub fn from_last_access_time(meta: &fs::Metadata) -> FileTime {
|
||||
imp::from_last_access_time(meta).emulate_second_only_system()
|
||||
}
|
||||
|
||||
/// Creates a new timestamp from the creation time listed in the specified
|
||||
/// metadata.
|
||||
///
|
||||
/// The returned value corresponds to the `birthtime` field of `stat` on
|
||||
/// Unix platforms and the `ftCreationTime` field on Windows platforms. Note
|
||||
/// that not all Unix platforms have this field available and may return
|
||||
/// `None` in some circumstances.
|
||||
pub fn from_creation_time(meta: &fs::Metadata) -> Option<FileTime> {
|
||||
imp::from_creation_time(meta).map(|x| x.emulate_second_only_system())
|
||||
}
|
||||
|
||||
/// Creates a new timestamp from the given SystemTime.
|
||||
///
|
||||
/// Windows counts file times since 1601-01-01T00:00:00Z, and cannot
|
||||
/// represent times before this, but it's possible to create a SystemTime
|
||||
/// that does. This function will error if passed such a SystemTime.
|
||||
pub fn from_system_time(time: SystemTime) -> FileTime {
|
||||
let epoch = if cfg!(windows) {
|
||||
UNIX_EPOCH - Duration::from_secs(11644473600)
|
||||
} else {
|
||||
UNIX_EPOCH
|
||||
};
|
||||
|
||||
time.duration_since(epoch)
|
||||
.map(|d| FileTime {
|
||||
seconds: d.as_secs() as i64,
|
||||
nanos: 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 {
|
||||
seconds: -1 * until_epoch.as_secs() as i64 + sec_offset,
|
||||
nanos,
|
||||
}
|
||||
})
|
||||
.emulate_second_only_system()
|
||||
}
|
||||
|
||||
/// Returns the whole number of seconds represented by this timestamp.
|
||||
///
|
||||
/// Note that this value's meaning is **platform specific**. On Unix
|
||||
/// platform time stamps are typically relative to January 1, 1970, but on
|
||||
/// Windows platforms time stamps are relative to January 1, 1601.
|
||||
pub const fn seconds(&self) -> i64 {
|
||||
self.seconds
|
||||
}
|
||||
|
||||
/// Returns the whole number of seconds represented by this timestamp,
|
||||
/// relative to the Unix epoch start of January 1, 1970.
|
||||
///
|
||||
/// Note that this does not return the same value as `seconds` for Windows
|
||||
/// platforms as seconds are relative to a different date there.
|
||||
pub const fn unix_seconds(&self) -> i64 {
|
||||
self.seconds - if cfg!(windows) { 11644473600 } else { 0 }
|
||||
}
|
||||
|
||||
/// Returns the nanosecond precision of this timestamp.
|
||||
///
|
||||
/// The returned value is always less than one billion and represents a
|
||||
/// portion of a second forward from the seconds returned by the `seconds`
|
||||
/// method.
|
||||
pub const fn nanoseconds(&self) -> u32 {
|
||||
self.nanos
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FileTime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}.{:09}s", self.seconds, self.nanos)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SystemTime> for FileTime {
|
||||
fn from(time: SystemTime) -> FileTime {
|
||||
FileTime::from_system_time(time)
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the last access and modification times for a file on the filesystem.
|
||||
///
|
||||
/// This function will set the `atime` and `mtime` metadata fields for a file
|
||||
/// on the local filesystem, returning any error encountered.
|
||||
pub fn set_file_times<P>(p: P, atime: FileTime, mtime: FileTime) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
imp::set_file_times(p.as_ref(), atime, mtime)
|
||||
}
|
||||
|
||||
/// Set the last access and modification times for a file handle.
|
||||
///
|
||||
/// This function will either or both of the `atime` and `mtime` metadata
|
||||
/// fields for a file handle , returning any error encountered. If `None` is
|
||||
/// specified then the time won't be updated. If `None` is specified for both
|
||||
/// options then no action is taken.
|
||||
pub fn set_file_handle_times(
|
||||
f: &fs::File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
imp::set_file_handle_times(f, atime, mtime)
|
||||
}
|
||||
|
||||
/// Set the last access and modification times for a file on the filesystem.
|
||||
/// This function does not follow symlink.
|
||||
///
|
||||
/// This function will set the `atime` and `mtime` metadata fields for a file
|
||||
/// on the local filesystem, returning any error encountered.
|
||||
pub fn set_symlink_file_times<P>(p: P, atime: FileTime, mtime: FileTime) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
imp::set_symlink_file_times(p.as_ref(), atime, mtime)
|
||||
}
|
||||
|
||||
/// Set the last modification time for a file on the filesystem.
|
||||
///
|
||||
/// This function will set the `mtime` metadata field for a file on the local
|
||||
/// filesystem, returning any error encountered.
|
||||
///
|
||||
/// # Platform support
|
||||
///
|
||||
/// Where supported this will attempt to issue just one syscall to update only
|
||||
/// the `mtime`, but where not supported this may issue one syscall to learn the
|
||||
/// existing `atime` so only the `mtime` can be configured.
|
||||
pub fn set_file_mtime<P>(p: P, mtime: FileTime) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
imp::set_file_mtime(p.as_ref(), mtime)
|
||||
}
|
||||
|
||||
/// Set the last access time for a file on the filesystem.
|
||||
///
|
||||
/// This function will set the `atime` metadata field for a file on the local
|
||||
/// filesystem, returning any error encountered.
|
||||
///
|
||||
/// # Platform support
|
||||
///
|
||||
/// Where supported this will attempt to issue just one syscall to update only
|
||||
/// the `atime`, but where not supported this may issue one syscall to learn the
|
||||
/// existing `mtime` so only the `atime` can be configured.
|
||||
pub fn set_file_atime<P>(p: P, atime: FileTime) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
imp::set_file_atime(p.as_ref(), atime)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
set_file_atime, set_file_handle_times, set_file_mtime, set_file_times,
|
||||
set_symlink_file_times, FileTime,
|
||||
};
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::time::{Duration, UNIX_EPOCH};
|
||||
use tempfile::Builder;
|
||||
|
||||
#[cfg(unix)]
|
||||
fn make_symlink_file<P, Q>(src: P, dst: Q) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
use std::os::unix::fs::symlink;
|
||||
symlink(src, dst)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn make_symlink_file<P, Q>(src: P, dst: Q) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
use std::os::windows::fs::symlink_file;
|
||||
symlink_file(src, dst)
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn make_symlink_dir<P, Q>(src: P, dst: Q) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
use std::os::unix::fs::symlink;
|
||||
symlink(src, dst)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn make_symlink_dir<P, Q>(src: P, dst: Q) -> io::Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
use std::os::windows::fs::symlink_dir;
|
||||
symlink_dir(src, dst)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn from_unix_time_test() {
|
||||
let time = FileTime::from_unix_time(10, 100_000_000);
|
||||
assert_eq!(11644473610, time.seconds);
|
||||
assert_eq!(100_000_000, time.nanos);
|
||||
|
||||
let time = FileTime::from_unix_time(-10, 100_000_000);
|
||||
assert_eq!(11644473590, time.seconds);
|
||||
assert_eq!(100_000_000, time.nanos);
|
||||
|
||||
let time = FileTime::from_unix_time(-12_000_000_000, 0);
|
||||
assert_eq!(-355526400, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn from_unix_time_test() {
|
||||
let time = FileTime::from_unix_time(10, 100_000_000);
|
||||
assert_eq!(10, time.seconds);
|
||||
assert_eq!(100_000_000, time.nanos);
|
||||
|
||||
let time = FileTime::from_unix_time(-10, 100_000_000);
|
||||
assert_eq!(-10, time.seconds);
|
||||
assert_eq!(100_000_000, time.nanos);
|
||||
|
||||
let time = FileTime::from_unix_time(-12_000_000_000, 0);
|
||||
assert_eq!(-12_000_000_000, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn from_system_time_test() {
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH + Duration::from_secs(10));
|
||||
assert_eq!(11644473610, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH - Duration::from_secs(10));
|
||||
assert_eq!(11644473590, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH - Duration::from_millis(1100));
|
||||
assert_eq!(11644473598, time.seconds);
|
||||
assert_eq!(900_000_000, time.nanos);
|
||||
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH - Duration::from_secs(12_000_000_000));
|
||||
assert_eq!(-355526400, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn from_system_time_test() {
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH + Duration::from_secs(10));
|
||||
assert_eq!(10, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH - Duration::from_secs(10));
|
||||
assert_eq!(-10, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH - Duration::from_millis(1100));
|
||||
assert_eq!(-2, time.seconds);
|
||||
assert_eq!(900_000_000, time.nanos);
|
||||
|
||||
let time = FileTime::from_system_time(UNIX_EPOCH - Duration::from_secs(12_000_000));
|
||||
assert_eq!(-12_000_000, time.seconds);
|
||||
assert_eq!(0, time.nanos);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_file_times_test() -> io::Result<()> {
|
||||
let td = Builder::new().prefix("filetime").tempdir()?;
|
||||
let path = td.path().join("foo.txt");
|
||||
let mut f = File::create(&path)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_file_times(&path, atime, mtime)?;
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(10_000, 0);
|
||||
set_file_times(&path, atime, new_mtime)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification should be updated");
|
||||
|
||||
// Update just mtime
|
||||
let new_mtime = FileTime::from_unix_time(20_000, 0);
|
||||
set_file_handle_times(&mut f, None, Some(new_mtime))?;
|
||||
let metadata = f.metadata()?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification time should be updated");
|
||||
let new_atime = FileTime::from_last_access_time(&metadata);
|
||||
assert_eq!(atime, new_atime, "accessed time should not be updated");
|
||||
|
||||
// Update just atime
|
||||
let new_atime = FileTime::from_unix_time(30_000, 0);
|
||||
set_file_handle_times(&mut f, Some(new_atime), None)?;
|
||||
let metadata = f.metadata()?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification time should not be updated");
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
assert_eq!(atime, new_atime, "accessed time should be updated");
|
||||
|
||||
let spath = td.path().join("bar.txt");
|
||||
make_symlink_file(&path, &spath)?;
|
||||
let metadata = fs::symlink_metadata(&spath)?;
|
||||
let smtime = FileTime::from_last_modification_time(&metadata);
|
||||
|
||||
set_file_times(&spath, atime, mtime)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let cur_mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, cur_mtime);
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath)?;
|
||||
let cur_mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(smtime, cur_mtime);
|
||||
|
||||
set_file_times(&spath, atime, new_mtime)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, smtime);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_dir_times_test() -> io::Result<()> {
|
||||
let td = Builder::new().prefix("filetime").tempdir()?;
|
||||
let path = td.path().join("foo");
|
||||
fs::create_dir(&path)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_file_times(&path, atime, mtime)?;
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(10_000, 0);
|
||||
set_file_times(&path, atime, new_mtime)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification should be updated");
|
||||
|
||||
// Update just mtime
|
||||
let new_mtime = FileTime::from_unix_time(20_000, 0);
|
||||
set_file_mtime(&path, new_mtime)?;
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification time should be updated");
|
||||
let new_atime = FileTime::from_last_access_time(&metadata);
|
||||
assert_eq!(atime, new_atime, "accessed time should not be updated");
|
||||
|
||||
// Update just atime
|
||||
let new_atime = FileTime::from_unix_time(30_000, 0);
|
||||
set_file_atime(&path, new_atime)?;
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification time should not be updated");
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
assert_eq!(atime, new_atime, "accessed time should be updated");
|
||||
|
||||
let spath = td.path().join("bar");
|
||||
make_symlink_dir(&path, &spath)?;
|
||||
let metadata = fs::symlink_metadata(&spath)?;
|
||||
let smtime = FileTime::from_last_modification_time(&metadata);
|
||||
|
||||
set_file_times(&spath, atime, mtime)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let cur_mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, cur_mtime);
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath)?;
|
||||
let cur_mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(smtime, cur_mtime);
|
||||
|
||||
set_file_times(&spath, atime, new_mtime)?;
|
||||
|
||||
let metadata = fs::metadata(&path)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath)?;
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, smtime);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_file_times_pre_unix_epoch_test() {
|
||||
let td = Builder::new().prefix("filetime").tempdir().unwrap();
|
||||
let path = td.path().join("foo.txt");
|
||||
File::create(&path).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_file_times(&path, atime, mtime).unwrap();
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(-10_000, 0);
|
||||
if cfg!(target_os = "aix") {
|
||||
// On AIX, os checks if the unix timestamp is valid.
|
||||
let result = set_file_times(&path, atime, new_mtime);
|
||||
assert!(result.is_err());
|
||||
assert!(result.err().unwrap().kind() == std::io::ErrorKind::InvalidInput);
|
||||
} else {
|
||||
set_file_times(&path, atime, new_mtime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn set_file_times_pre_windows_epoch_test() {
|
||||
let td = Builder::new().prefix("filetime").tempdir().unwrap();
|
||||
let path = td.path().join("foo.txt");
|
||||
File::create(&path).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_file_times(&path, atime, mtime).unwrap();
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(-12_000_000_000, 0);
|
||||
assert!(set_file_times(&path, atime, new_mtime).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_symlink_file_times_test() {
|
||||
let td = Builder::new().prefix("filetime").tempdir().unwrap();
|
||||
let path = td.path().join("foo.txt");
|
||||
File::create(&path).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_symlink_file_times(&path, atime, mtime).unwrap();
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(10_000, 0);
|
||||
set_symlink_file_times(&path, atime, new_mtime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let spath = td.path().join("bar.txt");
|
||||
make_symlink_file(&path, &spath).unwrap();
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath).unwrap();
|
||||
let smtime = FileTime::from_last_modification_time(&metadata);
|
||||
let satime = FileTime::from_last_access_time(&metadata);
|
||||
set_symlink_file_times(&spath, smtime, satime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let new_smtime = FileTime::from_unix_time(20_000, 0);
|
||||
set_symlink_file_times(&spath, atime, new_smtime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&spath).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_smtime);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_symlink_dir_times_test() {
|
||||
let td = Builder::new().prefix("filetime").tempdir().unwrap();
|
||||
let path = td.path().join("foo");
|
||||
fs::create_dir(&path).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_symlink_file_times(&path, atime, mtime).unwrap();
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(10_000, 0);
|
||||
set_symlink_file_times(&path, atime, new_mtime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let spath = td.path().join("bar");
|
||||
make_symlink_dir(&path, &spath).unwrap();
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath).unwrap();
|
||||
let smtime = FileTime::from_last_modification_time(&metadata);
|
||||
let satime = FileTime::from_last_access_time(&metadata);
|
||||
set_symlink_file_times(&spath, smtime, satime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let new_smtime = FileTime::from_unix_time(20_000, 0);
|
||||
set_symlink_file_times(&spath, atime, new_smtime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&spath).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime);
|
||||
|
||||
let metadata = fs::symlink_metadata(&spath).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_smtime);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_single_time_test() {
|
||||
use super::{set_file_atime, set_file_mtime};
|
||||
|
||||
let td = Builder::new().prefix("filetime").tempdir().unwrap();
|
||||
let path = td.path().join("foo.txt");
|
||||
File::create(&path).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
set_file_times(&path, atime, mtime).unwrap();
|
||||
|
||||
let new_mtime = FileTime::from_unix_time(10_000, 0);
|
||||
set_file_mtime(&path, new_mtime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let mtime = FileTime::from_last_modification_time(&metadata);
|
||||
assert_eq!(mtime, new_mtime, "modification time should be updated");
|
||||
assert_eq!(
|
||||
atime,
|
||||
FileTime::from_last_access_time(&metadata),
|
||||
"access time should not be updated",
|
||||
);
|
||||
|
||||
let new_atime = FileTime::from_unix_time(20_000, 0);
|
||||
set_file_atime(&path, new_atime).unwrap();
|
||||
|
||||
let metadata = fs::metadata(&path).unwrap();
|
||||
let atime = FileTime::from_last_access_time(&metadata);
|
||||
assert_eq!(atime, new_atime, "access time should be updated");
|
||||
assert_eq!(
|
||||
mtime,
|
||||
FileTime::from_last_modification_time(&metadata),
|
||||
"modification time should not be updated"
|
||||
);
|
||||
}
|
||||
}
|
||||
118
third-party/vendor/filetime/src/redox.rs
vendored
Normal file
118
third-party/vendor/filetime/src/redox.rs
vendored
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
use crate::FileTime;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
let fd = open_redox(p, 0).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
|
||||
let res = set_file_times_redox(fd, atime, mtime);
|
||||
let _ = syscall::close(fd);
|
||||
res
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
let fd = open_redox(p, 0).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
|
||||
let mut st = syscall::Stat::default();
|
||||
let res = match syscall::fstat(fd, &mut st) {
|
||||
Err(err) => Err(io::Error::from_raw_os_error(err.errno)),
|
||||
Ok(_) => set_file_times_redox(
|
||||
fd,
|
||||
FileTime {
|
||||
seconds: st.st_atime as i64,
|
||||
nanos: st.st_atime_nsec as u32,
|
||||
},
|
||||
mtime,
|
||||
),
|
||||
};
|
||||
let _ = syscall::close(fd);
|
||||
res
|
||||
}
|
||||
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
let fd = open_redox(p, 0).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
|
||||
let mut st = syscall::Stat::default();
|
||||
let res = match syscall::fstat(fd, &mut st) {
|
||||
Err(err) => Err(io::Error::from_raw_os_error(err.errno)),
|
||||
Ok(_) => set_file_times_redox(
|
||||
fd,
|
||||
atime,
|
||||
FileTime {
|
||||
seconds: st.st_mtime as i64,
|
||||
nanos: st.st_mtime_nsec as u32,
|
||||
},
|
||||
),
|
||||
};
|
||||
let _ = syscall::close(fd);
|
||||
res
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
let fd = open_redox(p, syscall::O_NOFOLLOW)
|
||||
.map_err(|err| io::Error::from_raw_os_error(err.errno))?;
|
||||
let res = set_file_times_redox(fd, atime, mtime);
|
||||
let _ = syscall::close(fd);
|
||||
res
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
f: &File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
let (atime1, mtime1) = match (atime, mtime) {
|
||||
(Some(a), Some(b)) => (a, b),
|
||||
(None, None) => return Ok(()),
|
||||
(Some(a), None) => {
|
||||
let meta = f.metadata()?;
|
||||
(a, FileTime::from_last_modification_time(&meta))
|
||||
}
|
||||
(None, Some(b)) => {
|
||||
let meta = f.metadata()?;
|
||||
(FileTime::from_last_access_time(&meta), b)
|
||||
}
|
||||
};
|
||||
set_file_times_redox(f.as_raw_fd() as usize, atime1, mtime1)
|
||||
}
|
||||
|
||||
fn open_redox(path: &Path, flags: usize) -> syscall::Result<usize> {
|
||||
match path.to_str() {
|
||||
Some(string) => syscall::open(string, flags),
|
||||
None => Err(syscall::Error::new(syscall::EINVAL)),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_file_times_redox(fd: usize, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
use syscall::TimeSpec;
|
||||
|
||||
fn to_timespec(ft: &FileTime) -> TimeSpec {
|
||||
TimeSpec {
|
||||
tv_sec: ft.seconds(),
|
||||
tv_nsec: ft.nanoseconds() as i32,
|
||||
}
|
||||
}
|
||||
|
||||
let times = [to_timespec(&atime), to_timespec(&mtime)];
|
||||
match syscall::futimens(fd, ×) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(io::Error::from_raw_os_error(err.errno)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_last_modification_time(meta: &fs::Metadata) -> FileTime {
|
||||
FileTime {
|
||||
seconds: meta.mtime(),
|
||||
nanos: meta.mtime_nsec() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_last_access_time(meta: &fs::Metadata) -> FileTime {
|
||||
FileTime {
|
||||
seconds: meta.atime(),
|
||||
nanos: meta.atime_nsec() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_creation_time(_meta: &fs::Metadata) -> Option<FileTime> {
|
||||
None
|
||||
}
|
||||
63
third-party/vendor/filetime/src/unix/android.rs
vendored
Normal file
63
third-party/vendor/filetime/src/unix/android.rs
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use crate::FileTime;
|
||||
use std::ffi::CString;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, None, Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), None, false)
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
f: &File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
|
||||
// On Android NDK before version 19, `futimens` is not available.
|
||||
//
|
||||
// For better compatibility, we reimplement `futimens` using `utimensat`,
|
||||
// the same way as bionic libc uses it to implement `futimens`.
|
||||
let rc = unsafe { libc::utimensat(f.as_raw_fd(), core::ptr::null(), times.as_ptr(), 0) };
|
||||
if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), true)
|
||||
}
|
||||
|
||||
fn set_times(
|
||||
p: &Path,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
symlink: bool,
|
||||
) -> io::Result<()> {
|
||||
let flags = if symlink {
|
||||
libc::AT_SYMLINK_NOFOLLOW
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let p = CString::new(p.as_os_str().as_bytes())?;
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
let rc = unsafe { libc::utimensat(libc::AT_FDCWD, p.as_ptr(), times.as_ptr(), flags) };
|
||||
if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
}
|
||||
117
third-party/vendor/filetime/src/unix/linux.rs
vendored
Normal file
117
third-party/vendor/filetime/src/unix/linux.rs
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
//! On Linux we try to use the more accurate `utimensat` syscall but this isn't
|
||||
//! always available so we also fall back to `utimes` if we couldn't find
|
||||
//! `utimensat` at runtime.
|
||||
|
||||
use crate::FileTime;
|
||||
use std::ffi::CString;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, None, Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), None, false)
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
f: &fs::File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
// Attempt to use the `utimensat` syscall, but if it's not supported by the
|
||||
// current kernel then fall back to an older syscall.
|
||||
static INVALID: AtomicBool = AtomicBool::new(false);
|
||||
if !INVALID.load(SeqCst) {
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
|
||||
// We normally use a syscall because the `utimensat` function is documented
|
||||
// as not accepting a file descriptor in the first argument (even though, on
|
||||
// Linux, the syscall itself can accept a file descriptor there).
|
||||
#[cfg(not(target_env = "musl"))]
|
||||
let rc = unsafe {
|
||||
libc::syscall(
|
||||
libc::SYS_utimensat,
|
||||
f.as_raw_fd(),
|
||||
ptr::null::<libc::c_char>(),
|
||||
times.as_ptr(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
// However, on musl, we call the musl libc function instead. This is because
|
||||
// on newer musl versions starting with musl 1.2, `timespec` is always a 64-bit
|
||||
// value even on 32-bit targets. As a result, musl internally converts their
|
||||
// `timespec` values to the correct ABI before invoking the syscall. Since we
|
||||
// use `timespec` from the libc crate, it matches musl's definition and not
|
||||
// the Linux kernel's version (for some platforms) so we must use musl's
|
||||
// `utimensat` function to properly convert the value. musl's `utimensat`
|
||||
// function allows file descriptors in the path argument so this is fine.
|
||||
#[cfg(target_env = "musl")]
|
||||
let rc = unsafe {
|
||||
libc::utimensat(
|
||||
f.as_raw_fd(),
|
||||
ptr::null::<libc::c_char>(),
|
||||
times.as_ptr(),
|
||||
0,
|
||||
)
|
||||
};
|
||||
|
||||
if rc == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let err = io::Error::last_os_error();
|
||||
if err.raw_os_error() == Some(libc::ENOSYS) {
|
||||
INVALID.store(true, SeqCst);
|
||||
} else {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
super::utimes::set_file_handle_times(f, atime, mtime)
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), true)
|
||||
}
|
||||
|
||||
fn set_times(
|
||||
p: &Path,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
symlink: bool,
|
||||
) -> io::Result<()> {
|
||||
let flags = if symlink {
|
||||
libc::AT_SYMLINK_NOFOLLOW
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
// Same as the `if` statement above.
|
||||
static INVALID: AtomicBool = AtomicBool::new(false);
|
||||
if !INVALID.load(SeqCst) {
|
||||
let p = CString::new(p.as_os_str().as_bytes())?;
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
let rc = unsafe { libc::utimensat(libc::AT_FDCWD, p.as_ptr(), times.as_ptr(), flags) };
|
||||
if rc == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
let err = io::Error::last_os_error();
|
||||
if err.raw_os_error() == Some(libc::ENOSYS) {
|
||||
INVALID.store(true, SeqCst);
|
||||
} else {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
super::utimes::set_times(p, atime, mtime, symlink)
|
||||
}
|
||||
108
third-party/vendor/filetime/src/unix/macos.rs
vendored
Normal file
108
third-party/vendor/filetime/src/unix/macos.rs
vendored
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
//! Beginning with macOS 10.13, `utimensat` is supported by the OS, so here, we check if the symbol exists
|
||||
//! and if not, we fallback to `utimes`.
|
||||
use crate::FileTime;
|
||||
use libc::{c_char, c_int, timespec};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::fs::File;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::{io, mem};
|
||||
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, None, Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), None, false)
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
f: &File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
// Attempt to use the `futimens` syscall, but if it's not supported by the
|
||||
// current kernel then fall back to an older syscall.
|
||||
if let Some(func) = futimens() {
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
let rc = unsafe { func(f.as_raw_fd(), times.as_ptr()) };
|
||||
if rc == 0 {
|
||||
return Ok(());
|
||||
} else {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
|
||||
super::utimes::set_file_handle_times(f, atime, mtime)
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), true)
|
||||
}
|
||||
|
||||
fn set_times(
|
||||
p: &Path,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
symlink: bool,
|
||||
) -> io::Result<()> {
|
||||
// Attempt to use the `utimensat` syscall, but if it's not supported by the
|
||||
// current kernel then fall back to an older syscall.
|
||||
if let Some(func) = utimensat() {
|
||||
let flags = if symlink {
|
||||
libc::AT_SYMLINK_NOFOLLOW
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let p = CString::new(p.as_os_str().as_bytes())?;
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
let rc = unsafe { func(libc::AT_FDCWD, p.as_ptr(), times.as_ptr(), flags) };
|
||||
if rc == 0 {
|
||||
return Ok(());
|
||||
} else {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
|
||||
super::utimes::set_times(p, atime, mtime, symlink)
|
||||
}
|
||||
|
||||
fn utimensat() -> Option<unsafe extern "C" fn(c_int, *const c_char, *const timespec, c_int) -> c_int>
|
||||
{
|
||||
static ADDR: AtomicUsize = AtomicUsize::new(0);
|
||||
unsafe {
|
||||
fetch(&ADDR, CStr::from_bytes_with_nul_unchecked(b"utimensat\0"))
|
||||
.map(|sym| mem::transmute(sym))
|
||||
}
|
||||
}
|
||||
|
||||
fn futimens() -> Option<unsafe extern "C" fn(c_int, *const timespec) -> c_int> {
|
||||
static ADDR: AtomicUsize = AtomicUsize::new(0);
|
||||
unsafe {
|
||||
fetch(&ADDR, CStr::from_bytes_with_nul_unchecked(b"futimens\0"))
|
||||
.map(|sym| mem::transmute(sym))
|
||||
}
|
||||
}
|
||||
|
||||
fn fetch(cache: &AtomicUsize, name: &CStr) -> Option<usize> {
|
||||
match cache.load(SeqCst) {
|
||||
0 => {}
|
||||
1 => return None,
|
||||
n => return Some(n),
|
||||
}
|
||||
let sym = unsafe { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr() as *const _) };
|
||||
let (val, ret) = if sym.is_null() {
|
||||
(1, None)
|
||||
} else {
|
||||
(sym as usize, Some(sym as usize))
|
||||
};
|
||||
cache.store(val, SeqCst);
|
||||
return ret;
|
||||
}
|
||||
101
third-party/vendor/filetime/src/unix/mod.rs
vendored
Normal file
101
third-party/vendor/filetime/src/unix/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
use crate::FileTime;
|
||||
use libc::{time_t, timespec};
|
||||
use std::fs;
|
||||
use std::os::unix::prelude::*;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "linux")] {
|
||||
mod utimes;
|
||||
mod linux;
|
||||
pub use self::linux::*;
|
||||
} else if #[cfg(target_os = "android")] {
|
||||
mod android;
|
||||
pub use self::android::*;
|
||||
} else if #[cfg(target_os = "macos")] {
|
||||
mod utimes;
|
||||
mod macos;
|
||||
pub use self::macos::*;
|
||||
} else if #[cfg(any(target_os = "aix",
|
||||
target_os = "solaris",
|
||||
target_os = "illumos",
|
||||
target_os = "emscripten",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "haiku"))] {
|
||||
mod utimensat;
|
||||
pub use self::utimensat::*;
|
||||
} else {
|
||||
mod utimes;
|
||||
pub use self::utimes::*;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn to_timespec(ft: &Option<FileTime>) -> timespec {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(target_os = "macos",
|
||||
target_os = "illumos",
|
||||
target_os = "freebsd"))] {
|
||||
// https://github.com/apple/darwin-xnu/blob/a449c6a3b8014d9406c2ddbdc81795da24aa7443/bsd/sys/stat.h#L541
|
||||
// https://github.com/illumos/illumos-gate/blob/master/usr/src/boot/sys/sys/stat.h#L312
|
||||
// https://svnweb.freebsd.org/base/head/sys/sys/stat.h?view=markup#l359
|
||||
const UTIME_OMIT: i64 = -2;
|
||||
} else if #[cfg(target_os = "openbsd")] {
|
||||
// https://github.com/openbsd/src/blob/master/sys/sys/stat.h#L189
|
||||
const UTIME_OMIT: i64 = -1;
|
||||
} else if #[cfg(target_os = "haiku")] {
|
||||
// https://git.haiku-os.org/haiku/tree/headers/posix/sys/stat.h?#n106
|
||||
const UTIME_OMIT: i64 = 1000000001;
|
||||
} else if #[cfg(target_os = "aix")] {
|
||||
// AIX hasn't disclosed system header files yet.
|
||||
// https://github.com/golang/go/blob/master/src/cmd/vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go#L1007
|
||||
const UTIME_OMIT: i64 = -3;
|
||||
} else {
|
||||
// http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/stat.h?annotate=1.68.30.1
|
||||
// https://github.com/emscripten-core/emscripten/blob/master/system/include/libc/sys/stat.h#L71
|
||||
const UTIME_OMIT: i64 = 1_073_741_822;
|
||||
}
|
||||
}
|
||||
|
||||
let mut ts: timespec = unsafe { std::mem::zeroed() };
|
||||
if let &Some(ft) = ft {
|
||||
ts.tv_sec = ft.seconds() as time_t;
|
||||
ts.tv_nsec = ft.nanoseconds() as _;
|
||||
} else {
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = UTIME_OMIT as _;
|
||||
}
|
||||
|
||||
ts
|
||||
}
|
||||
|
||||
pub fn from_last_modification_time(meta: &fs::Metadata) -> FileTime {
|
||||
FileTime {
|
||||
seconds: meta.mtime(),
|
||||
nanos: meta.mtime_nsec() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_last_access_time(meta: &fs::Metadata) -> FileTime {
|
||||
FileTime {
|
||||
seconds: meta.atime(),
|
||||
nanos: meta.atime_nsec() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_creation_time(meta: &fs::Metadata) -> Option<FileTime> {
|
||||
#[cfg(target_os = "bitrig")]
|
||||
{
|
||||
use std::os::bitrig::fs::MetadataExt;
|
||||
Some(FileTime {
|
||||
seconds: meta.st_birthtime(),
|
||||
nanos: meta.st_birthtime_nsec() as u32,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "bitrig"))]
|
||||
{
|
||||
meta.created().map(|i| i.into()).ok()
|
||||
}
|
||||
}
|
||||
64
third-party/vendor/filetime/src/unix/utimensat.rs
vendored
Normal file
64
third-party/vendor/filetime/src/unix/utimensat.rs
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use crate::FileTime;
|
||||
use std::ffi::CString;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, None, Some(mtime), false)
|
||||
}
|
||||
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), None, false)
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
f: &File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
let rc = unsafe { libc::futimens(f.as_raw_fd(), times.as_ptr()) };
|
||||
if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), true)
|
||||
}
|
||||
|
||||
fn set_times(
|
||||
p: &Path,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
symlink: bool,
|
||||
) -> io::Result<()> {
|
||||
let flags = if symlink {
|
||||
if cfg!(target_os = "emscripten") {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"emscripten does not support utimensat for symlinks",
|
||||
));
|
||||
}
|
||||
libc::AT_SYMLINK_NOFOLLOW
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let p = CString::new(p.as_os_str().as_bytes())?;
|
||||
let times = [super::to_timespec(&atime), super::to_timespec(&mtime)];
|
||||
let rc = unsafe { libc::utimensat(libc::AT_FDCWD, p.as_ptr(), times.as_ptr(), flags) };
|
||||
if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
}
|
||||
130
third-party/vendor/filetime/src/unix/utimes.rs
vendored
Normal file
130
third-party/vendor/filetime/src/unix/utimes.rs
vendored
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
use crate::FileTime;
|
||||
use std::ffi::CString;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), false)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, None, Some(mtime), false)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), None, false)
|
||||
}
|
||||
|
||||
#[cfg(not(target_env = "uclibc"))]
|
||||
#[allow(dead_code)]
|
||||
pub fn set_file_handle_times(
|
||||
f: &fs::File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
let (atime, mtime) = match get_times(atime, mtime, || f.metadata())? {
|
||||
Some(pair) => pair,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let times = [to_timeval(&atime), to_timeval(&mtime)];
|
||||
let rc = unsafe { libc::futimes(f.as_raw_fd(), times.as_ptr()) };
|
||||
return if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(target_env = "uclibc")]
|
||||
#[allow(dead_code)]
|
||||
pub fn set_file_handle_times(
|
||||
f: &fs::File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
let (atime, mtime) = match get_times(atime, mtime, || f.metadata())? {
|
||||
Some(pair) => pair,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let times = [to_timespec(&atime), to_timespec(&mtime)];
|
||||
let rc = unsafe { libc::futimens(f.as_raw_fd(), times.as_ptr()) };
|
||||
return if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
};
|
||||
}
|
||||
|
||||
fn get_times(
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
current: impl FnOnce() -> io::Result<fs::Metadata>,
|
||||
) -> io::Result<Option<(FileTime, FileTime)>> {
|
||||
let pair = match (atime, mtime) {
|
||||
(Some(a), Some(b)) => (a, b),
|
||||
(None, None) => return Ok(None),
|
||||
(Some(a), None) => {
|
||||
let meta = current()?;
|
||||
(a, FileTime::from_last_modification_time(&meta))
|
||||
}
|
||||
(None, Some(b)) => {
|
||||
let meta = current()?;
|
||||
(FileTime::from_last_access_time(&meta), b)
|
||||
}
|
||||
};
|
||||
Ok(Some(pair))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
set_times(p, Some(atime), Some(mtime), true)
|
||||
}
|
||||
|
||||
pub fn set_times(
|
||||
p: &Path,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
symlink: bool,
|
||||
) -> io::Result<()> {
|
||||
let (atime, mtime) = match get_times(atime, mtime, || p.metadata())? {
|
||||
Some(pair) => pair,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let p = CString::new(p.as_os_str().as_bytes())?;
|
||||
let times = [to_timeval(&atime), to_timeval(&mtime)];
|
||||
let rc = unsafe {
|
||||
if symlink {
|
||||
libc::lutimes(p.as_ptr(), times.as_ptr())
|
||||
} else {
|
||||
libc::utimes(p.as_ptr(), times.as_ptr())
|
||||
}
|
||||
};
|
||||
return if rc == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
};
|
||||
}
|
||||
|
||||
fn to_timeval(ft: &FileTime) -> libc::timeval {
|
||||
libc::timeval {
|
||||
tv_sec: ft.seconds() as libc::time_t,
|
||||
tv_usec: (ft.nanoseconds() / 1000) as libc::suseconds_t,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_env = "uclibc")]
|
||||
fn to_timespec(ft: &FileTime) -> libc::timespec {
|
||||
libc::timespec {
|
||||
tv_sec: ft.seconds() as libc::time_t,
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
|
||||
tv_nsec: (ft.nanoseconds()) as i64,
|
||||
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
|
||||
tv_nsec: (ft.nanoseconds()) as libc::c_long,
|
||||
}
|
||||
}
|
||||
40
third-party/vendor/filetime/src/wasm.rs
vendored
Normal file
40
third-party/vendor/filetime/src/wasm.rs
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use crate::FileTime;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn set_file_times(_p: &Path, _atime: FileTime, _mtime: FileTime) -> io::Result<()> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Wasm not implemented"))
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(_p: &Path, _atime: FileTime, _mtime: FileTime) -> io::Result<()> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Wasm not implemented"))
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(_p: &Path, _mtime: FileTime) -> io::Result<()> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Wasm not implemented"))
|
||||
}
|
||||
|
||||
pub fn set_file_atime(_p: &Path, _atime: FileTime) -> io::Result<()> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Wasm not implemented"))
|
||||
}
|
||||
|
||||
pub fn from_last_modification_time(_meta: &fs::Metadata) -> FileTime {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn from_last_access_time(_meta: &fs::Metadata) -> FileTime {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn from_creation_time(_meta: &fs::Metadata) -> Option<FileTime> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
_f: &File,
|
||||
_atime: Option<FileTime>,
|
||||
_mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Wasm not implemented"))
|
||||
}
|
||||
99
third-party/vendor/filetime/src/windows.rs
vendored
Normal file
99
third-party/vendor/filetime/src/windows.rs
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
use crate::FileTime;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io;
|
||||
use std::os::windows::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use windows_sys::Win32::Foundation::{FILETIME, HANDLE};
|
||||
use windows_sys::Win32::Storage::FileSystem::*;
|
||||
|
||||
pub fn set_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
let f = OpenOptions::new()
|
||||
.write(true)
|
||||
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
|
||||
.open(p)?;
|
||||
set_file_handle_times(&f, Some(atime), Some(mtime))
|
||||
}
|
||||
|
||||
pub fn set_file_mtime(p: &Path, mtime: FileTime) -> io::Result<()> {
|
||||
let f = OpenOptions::new()
|
||||
.write(true)
|
||||
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
|
||||
.open(p)?;
|
||||
set_file_handle_times(&f, None, Some(mtime))
|
||||
}
|
||||
|
||||
pub fn set_file_atime(p: &Path, atime: FileTime) -> io::Result<()> {
|
||||
let f = OpenOptions::new()
|
||||
.write(true)
|
||||
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
|
||||
.open(p)?;
|
||||
set_file_handle_times(&f, Some(atime), None)
|
||||
}
|
||||
|
||||
pub fn set_file_handle_times(
|
||||
f: &File,
|
||||
atime: Option<FileTime>,
|
||||
mtime: Option<FileTime>,
|
||||
) -> io::Result<()> {
|
||||
let atime = atime.map(to_filetime);
|
||||
let mtime = mtime.map(to_filetime);
|
||||
return unsafe {
|
||||
let ret = SetFileTime(
|
||||
f.as_raw_handle() as HANDLE,
|
||||
ptr::null(),
|
||||
atime
|
||||
.as_ref()
|
||||
.map(|p| p as *const FILETIME)
|
||||
.unwrap_or(ptr::null()),
|
||||
mtime
|
||||
.as_ref()
|
||||
.map(|p| p as *const FILETIME)
|
||||
.unwrap_or(ptr::null()),
|
||||
);
|
||||
if ret != 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
};
|
||||
|
||||
fn to_filetime(ft: FileTime) -> FILETIME {
|
||||
let intervals = ft.seconds() * (1_000_000_000 / 100) + ((ft.nanoseconds() as i64) / 100);
|
||||
FILETIME {
|
||||
dwLowDateTime: intervals as u32,
|
||||
dwHighDateTime: (intervals >> 32) as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_symlink_file_times(p: &Path, atime: FileTime, mtime: FileTime) -> io::Result<()> {
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
|
||||
let f = OpenOptions::new()
|
||||
.write(true)
|
||||
.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS)
|
||||
.open(p)?;
|
||||
set_file_handle_times(&f, Some(atime), Some(mtime))
|
||||
}
|
||||
|
||||
pub fn from_last_modification_time(meta: &fs::Metadata) -> FileTime {
|
||||
from_intervals(meta.last_write_time())
|
||||
}
|
||||
|
||||
pub fn from_last_access_time(meta: &fs::Metadata) -> FileTime {
|
||||
from_intervals(meta.last_access_time())
|
||||
}
|
||||
|
||||
pub fn from_creation_time(meta: &fs::Metadata) -> Option<FileTime> {
|
||||
Some(from_intervals(meta.creation_time()))
|
||||
}
|
||||
|
||||
fn from_intervals(ticks: u64) -> FileTime {
|
||||
// Windows write times are in 100ns intervals, so do a little math to
|
||||
// get it into the right representation.
|
||||
FileTime {
|
||||
seconds: (ticks / (1_000_000_000 / 100)) as i64,
|
||||
nanos: ((ticks % (1_000_000_000 / 100)) * 100) as u32,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue