[blivet] Allow / in StorageDevice names (#1103751)
David Lehman
dlehman at redhat.com
Tue Jun 3 15:11:32 UTC 2014
On 06/03/2014 08:39 AM, David Shea wrote:
> ---
> blivet/devices.py | 11 ++---------
> tests/devices_test.py | 4 ++--
> 2 files changed, 4 insertions(+), 11 deletions(-)
It's probably worthwhile to differentiate which classes do and do not
allow slashes in device names. Disks and partitions can contain them,
but only if the name starts with cciss/. Files, directories, btrfs
subvolumes, and nfs devices can contain them. Nothing else can, unless
I'm forgetting something even more obscure than CCISS.
David
>
> diff --git a/blivet/devices.py b/blivet/devices.py
> index cdd0642..24610aa 100644
> --- a/blivet/devices.py
> +++ b/blivet/devices.py
> @@ -1118,10 +1118,8 @@ class StorageDevice(Device):
>
> @classmethod
> def isNameValid(cls, name):
> - # This device corresponds to a file in /dev, so no /'s or nulls,
> - # and the name cannot be . or ..
> - badchars = any(c in ('\x00', '/') for c in name)
> - return not(badchars or name == '.' or name == '..')
> + # Allow any character except NUL, disallow . and ..
> + return not('\x00' in name or name == '.' or name == '..')
>
> class DiskDevice(StorageDevice):
> """ A local/generic disk.
> @@ -4143,11 +4141,6 @@ class FileDevice(StorageDevice):
> log_method_call(self, self.name, status=self.status)
> os.unlink(self.path)
>
> - @classmethod
> - def isNameValid(cls, name):
> - # Override StorageDevice.isNameValid to allow /
> - return not('\x00' in name or name == '.' or name == '..')
> -
> class SparseFileDevice(FileDevice):
> """A sparse file on a filesystem.
> This exists for sparse disk images."""
> diff --git a/tests/devices_test.py b/tests/devices_test.py
> index 6598eba..6f6f547 100644
> --- a/tests/devices_test.py
> +++ b/tests/devices_test.py
> @@ -508,8 +508,8 @@ class DeviceNameTestCase(unittest.TestCase):
>
> def testStorageDefvice(self):
> # Check that / and NUL are rejected along with . and ..
> - good_names = ['sda1', '1sda', 'good-name']
> - bad_names = ['sda/1', 'sda\x00', '.', '..']
> + good_names = ['sda1', '1sda', 'good-name', 'sda/1']
> + bad_names = ['sda\x00', '.', '..']
>
> for name in good_names:
> self.assertTrue(StorageDevice.isNameValid(name))
>
More information about the anaconda-patches
mailing list