From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Maximiliano Sandoval <m.sandoval@proxmox.com>
Subject: Re: [pbs-devel] [PATCH backup v3] fix-3699: pbs-client/tools: use xdg basedirectories for tmp files
Date: Mon, 5 Feb 2024 17:15:28 +0100 [thread overview]
Message-ID: <4a7cffae-72d9-440c-8997-b5450b8a9339@proxmox.com> (raw)
In-Reply-To: <20240201134944.525535-1-m.sandoval@proxmox.com>
please keep to the commonly used `fix #id: ...` format for the subject,
the correct that would "client" here, and could be slightly reworded to
better convey what's done here, e.g. something like:
fix #3699: client: prefer xdg cache directory for tmp files
Am 01/02/2024 um 14:49 schrieb Maximiliano Sandoval:
> Adds a helper to create temporal files in XDG_CACHE_HOME. If the we
> cannot use that path, we fallback to /tmp as before.
>
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
> Differences from v2:
> - Files are created at XDG_CACHE_HOME directly
> - If opening fails, we try opening at /tmp
> - We check if the directory exists as part of the error handling of open()
>
> pbs-client/src/backup_reader.rs | 31 ++++++++--------------------
> pbs-client/src/backup_writer.rs | 13 ++----------
> pbs-client/src/tools/mod.rs | 26 +++++++++++++++++++++++
> proxmox-backup-client/src/catalog.rs | 19 +++--------------
> 4 files changed, 40 insertions(+), 49 deletions(-)
>
> diff --git a/pbs-client/src/backup_reader.rs b/pbs-client/src/backup_reader.rs
> index 36d8ebcf..6483f5b2 100644
> --- a/pbs-client/src/backup_reader.rs
> +++ b/pbs-client/src/backup_reader.rs
> @@ -141,18 +140,14 @@ impl BackupReader {
>
> /// Download a .blob file
> ///
> - /// This creates a temporary file in /tmp (using O_TMPFILE). The data is verified using
> - /// the provided manifest.
> + /// This creates a temporary file (using O_TMPFILE). The data is verified
I'd keep the location info, or better, refer to the underlying
"create_tmp_file" function with a docs link so that it can be easily
checked out w.r.t. semantics.
> + /// using the provided manifest.
> diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs
> index 1b0123a3..a721fbc4 100644
> --- a/pbs-client/src/tools/mod.rs
> +++ b/pbs-client/src/tools/mod.rs
> @@ -526,3 +528,27 @@ pub fn place_xdg_file(
> .and_then(|base| base.place_config_file(file_name).map_err(Error::from))
> .with_context(|| format!("failed to place {} in xdg home", description))
> }
> +
> +/// Creates a temporary file (created with O_TMPFILE) in either XDG_CACHE_HOME
> +/// if the directory exists, otherwise it will be created in /tmp otherwise.
duplicate "otherwise", could be fixed up on applying though.
> +pub fn create_tmp_file() -> std::io::Result<std::fs::File> {
Hmm, wondering if "create_xdg_tmp_file" could be slightly better here,
but the fallback behavior is not the best fit with that name, so no
hard feelings from my side.
> + static TMP_PATH: OnceLock<std::path::PathBuf> = OnceLock::new();
> + let tmp_path = TMP_PATH.get_or_init(|| {
> + xdg::BaseDirectories::new()
> + .map(|base| base.xdg_cache_dir())
I'm really not to sure if the cache one is the best fit, but it certainly
isn't wrong either.
What I'd like though is some sentence w.r.t. choosing this over the
runtime one in the commit message, i.e., one that states that there isn't
an explicit one for temporary files and that both, run and cache ones,
would be OK choices, but we choose the cache one <arbitrarily|$reasons>
> + .unwrap_or_else(|| std::path::PathBuf::from("/tmp"))
> + });
> +
> + let mut open_opts_binding = std::fs::OpenOptions::new();
> + let builder = open_opts_binding
> + .write(true)
> + .read(true)
> + .custom_flags(libc::O_TMPFILE);
> + builder.open(tmp_path).or_else(|err| {
> + if tmp_path != std::path::Path::new("/tmp") {
> + builder.open("/tmp")
> + } else {
> + Err(err)
> + }
> + })
> +}
next prev parent reply other threads:[~2024-02-05 16:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 13:49 Maximiliano Sandoval
2024-02-05 16:15 ` Thomas Lamprecht [this message]
2024-02-12 9:46 ` Maximiliano Sandoval
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=4a7cffae-72d9-440c-8997-b5450b8a9339@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=m.sandoval@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