From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 2/6] tools/fs: add helpers to get the mtime of a file
Date: Fri, 6 Nov 2020 18:24:14 +0100 [thread overview]
Message-ID: <9f89bd33-1afb-fd68-3333-25f53c4210b0@proxmox.com> (raw)
In-Reply-To: <20201106100343.12161-3-d.csapak@proxmox.com>
On 06.11.20 11:03, Dominik Csapak wrote:
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> src/tools/fs.rs | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/src/tools/fs.rs b/src/tools/fs.rs
> index 72a530d8..d7ab934a 100644
> --- a/src/tools/fs.rs
> +++ b/src/tools/fs.rs
> @@ -312,3 +312,25 @@ fn do_lock_dir_noblock(
>
> Ok(handle)
> }
> +
> +pub fn get_file_mtime<P: AsRef<std::path::Path>>(path: P) -> Result<i64, Error> {
> + let time = std::fs::metadata(path)?.modified()?;
> +
> + let mtime: i64 = if time < std::time::SystemTime::UNIX_EPOCH {
> + -(std::time::SystemTime::UNIX_EPOCH.duration_since(time)?.as_secs() as i64)
> + } else {
> + time.duration_since(std::time::SystemTime::UNIX_EPOCH)?.as_secs() as i64
> + };
> + Ok(mtime)
> +}
> +
> +pub async fn get_async_file_mtime<P: AsRef<std::path::Path>>(path: P) -> Result<i64, Error> {
> + let time = tokio::fs::metadata(path).await?.modified()?;
> +
> + let mtime: i64 = if time < std::time::SystemTime::UNIX_EPOCH {
> + -(std::time::SystemTime::UNIX_EPOCH.duration_since(time)?.as_secs() as i64)
> + } else {
> + time.duration_since(std::time::SystemTime::UNIX_EPOCH)?.as_secs() as i64
> + };
> + Ok(mtime)
> +}
>
wouldn't it be more sensible to implement just a system_time_to_i64 and use that
in combination with a "manual" modified call on use-site.
Avoids instancing multiple generics, and more flexible as one can have a file handle
or a path.
next prev parent reply other threads:[~2020-11-06 17:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-06 10:03 [pbs-devel] [PATCH proxmox-backup 0/6] improve caching behaviour for html resources Dominik Csapak
2020-11-06 10:03 ` [pbs-devel] [PATCH proxmox-backup 1/6] proxmox-backup-proxy: remove unnecessary alias Dominik Csapak
2020-11-06 18:05 ` [pbs-devel] applied: " Thomas Lamprecht
2020-11-06 10:03 ` [pbs-devel] [PATCH proxmox-backup 2/6] tools/fs: add helpers to get the mtime of a file Dominik Csapak
2020-11-06 17:24 ` Thomas Lamprecht [this message]
2020-11-06 10:03 ` [pbs-devel] [PATCH proxmox-backup 3/6] server/rest: set last-modified for static files Dominik Csapak
2020-11-06 13:14 ` Wolfgang Bumiller
2020-11-06 10:03 ` [pbs-devel] [PATCH proxmox-backup 4/6] server/config: add ability to get mtime of files for template Dominik Csapak
2020-11-06 13:22 ` Wolfgang Bumiller
2020-11-06 10:03 ` [pbs-devel] [PATCH proxmox-backup 5/6] proxmox-backup-proxy: add cache parameter to index Dominik Csapak
2020-11-06 10:03 ` [pbs-devel] [PATCH proxmox-backup 6/6] ui: set also extjs language Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f89bd33-1afb-fd68-3333-25f53c4210b0@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox