Blame SOURCES/0050-devices-file-fail-if-devicesfile-filename-doesn-t-ex.patch

ab86b0
From bf0b3962088fb18f4a2aba00f38955e1fc6e31fe Mon Sep 17 00:00:00 2001
ab86b0
From: David Teigland <teigland@redhat.com>
ab86b0
Date: Fri, 27 May 2022 14:27:03 -0500
ab86b0
Subject: [PATCH 50/54] devices file: fail if --devicesfile filename doesn't
ab86b0
 exist
ab86b0
ab86b0
A typo of the filename after --devicesfile should result in a
ab86b0
command error rather than the command falling back to using no
ab86b0
devices file at all.  Exception is vgcreate|pvcreate which
ab86b0
create a new devices file if the file name doesn't exist.
ab86b0
---
ab86b0
 lib/device/dev-cache.c          | 9 +++++++++
ab86b0
 test/shell/devicesfile-basic.sh | 4 ++++
ab86b0
 2 files changed, 13 insertions(+)
ab86b0
ab86b0
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
ab86b0
index b0759b06c..0eb2568b5 100644
ab86b0
--- a/lib/device/dev-cache.c
ab86b0
+++ b/lib/device/dev-cache.c
ab86b0
@@ -1882,6 +1882,15 @@ static int _setup_devices(struct cmd_context *cmd, int no_file_match)
ab86b0
 
ab86b0
 	file_exists = devices_file_exists(cmd);
ab86b0
 
ab86b0
+	/*
ab86b0
+	 * Fail if user specifies a file name that doesn't exist and
ab86b0
+	 * the command is not creating a new devices file.
ab86b0
+	 */
ab86b0
+	if (!file_exists && !cmd->create_edit_devices_file && cmd->devicesfile && strlen(cmd->devicesfile)) {
ab86b0
+		log_error("Devices file not found: %s", cmd->devices_file_path);
ab86b0
+		return 0;
ab86b0
+	}
ab86b0
+
ab86b0
 	/*
ab86b0
 	 * Removing the devices file is another way of disabling the use of
ab86b0
 	 * a devices file, unless the command creates the devices file.
ab86b0
diff --git a/test/shell/devicesfile-basic.sh b/test/shell/devicesfile-basic.sh
ab86b0
index 7ba9e2c7f..d1cfb6a35 100644
ab86b0
--- a/test/shell/devicesfile-basic.sh
ab86b0
+++ b/test/shell/devicesfile-basic.sh
ab86b0
@@ -104,6 +104,10 @@ not ls "$DFDIR/system.devices"
ab86b0
 vgs --devicesfile test.devices $vg1
ab86b0
 not vgs --devicesfile test.devices $vg2
ab86b0
 
ab86b0
+# misspelled override name fails
ab86b0
+not vgs --devicesfile doesnotexist $vg1
ab86b0
+not vgs --devicesfile doesnotexist $vg2
ab86b0
+
ab86b0
 # devicesfile and devices cannot be used together
ab86b0
 not vgs --devicesfile test.devices --devices "$dev1","$dev1" $vg1
ab86b0
 
ab86b0
-- 
ab86b0
2.34.3
ab86b0