From b44ee4cf54dcf69f294081b1e12603bf0a0e4c10 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 31 Jan 2023 15:27:54 +0000 Subject: [PATCH] trivial: Require --force to overwrite files with 'fwupdmgr download' --- src/fu-util.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fu-util.c b/src/fu-util.c index 7d0e43b56..351ecc318 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -1110,6 +1110,17 @@ fu_util_download(FuUtilPrivate *priv, gchar **values, GError **error) return FALSE; } + /* file already exists */ + basename = g_path_get_basename(values[0]); + if ((priv->flags & FWUPD_INSTALL_FLAG_FORCE) == 0 && + g_file_test(basename, G_FILE_TEST_EXISTS)) { + g_set_error(error, + FWUPD_ERROR, + FWUPD_ERROR_INVALID_ARGS, + "%s already exists", + basename); + return FALSE; + } blob = fwupd_client_download_bytes(priv->client, values[0], priv->download_flags, @@ -1117,7 +1128,6 @@ fu_util_download(FuUtilPrivate *priv, gchar **values, GError **error) error); if (blob == NULL) return FALSE; - basename = g_path_get_basename(values[0]); return g_file_set_contents(basename, g_bytes_get_data(blob, NULL), g_bytes_get_size(blob),