basic/path-util: do not say that /dev and /sys are device paths
"/dev" or "/dev/" is the mount point, not a device path. In particular, 'systemctl status /dev' clearly does not refer to a device, so let's tweak the code a bit to say that those are not device paths. (Treating "/../dev" same as "/dev" would be also be reasonable, but that requires chase(), which requires disk access, which we don't want to do from this lightweight function.)
This commit is contained in:
@@ -1272,9 +1272,16 @@ bool hidden_or_backup_file(const char *filename) {
|
||||
bool is_device_path(const char *path) {
|
||||
|
||||
/* Returns true for paths that likely refer to a device, either by path in sysfs or to something in
|
||||
* /dev. */
|
||||
* /dev. This accepts any path that starts with /dev/ or /sys/ and has something after that prefix.
|
||||
* It does not actually resolve the path.
|
||||
*
|
||||
* Examples:
|
||||
* /dev/sda, /dev/sda/foo, /sys/class, /dev/.., /sys/.., /./dev/foo → yes.
|
||||
* /../dev/sda, /dev, /sys, /usr/path, /usr/../dev/sda → no.
|
||||
*/
|
||||
|
||||
return PATH_STARTSWITH_SET(path, "/dev/", "/sys/");
|
||||
const char *p = PATH_STARTSWITH_SET(ASSERT_PTR(path), "/dev/", "/sys/");
|
||||
return !isempty(p);
|
||||
}
|
||||
|
||||
bool valid_device_node_path(const char *path) {
|
||||
|
||||
+14
-14
@@ -99,18 +99,18 @@ TEST(is_device_path) {
|
||||
assert_se(!is_device_path(""));
|
||||
assert_se(!is_device_path(".."));
|
||||
|
||||
assert_se( is_device_path("/dev"));
|
||||
assert_se( is_device_path("/./dev"));
|
||||
assert_se( is_device_path("/./dev/."));
|
||||
assert_se(!is_device_path("/dev"));
|
||||
assert_se(!is_device_path("/./dev"));
|
||||
assert_se(!is_device_path("/./dev/."));
|
||||
assert_se(!is_device_path("/./dev."));
|
||||
assert_se( is_device_path("/./dev/foo"));
|
||||
assert_se( is_device_path("/./dev/./foo"));
|
||||
assert_se(!is_device_path("/./dev./foo"));
|
||||
assert_se( is_device_path("//dev"));
|
||||
assert_se( is_device_path("///dev"));
|
||||
assert_se( is_device_path("/dev/"));
|
||||
assert_se( is_device_path("///dev/"));
|
||||
assert_se( is_device_path("/./dev/"));
|
||||
assert_se(!is_device_path("//dev"));
|
||||
assert_se(!is_device_path("///dev"));
|
||||
assert_se(!is_device_path("/dev/"));
|
||||
assert_se(!is_device_path("///dev/"));
|
||||
assert_se(!is_device_path("/./dev/"));
|
||||
assert_se(!is_device_path("/../dev/"));
|
||||
assert_se( is_device_path("/dev/sda"));
|
||||
assert_se( is_device_path("/dev/sda5"));
|
||||
@@ -120,10 +120,10 @@ TEST(is_device_path) {
|
||||
assert_se(!is_device_path("/../../dev/sda5"));
|
||||
assert_se(!is_device_path("/../../../dev/sda5b3"));
|
||||
assert_se(!is_device_path("/.././.././dev/sda5b3/idontexit"));
|
||||
assert_se( is_device_path("/sys"));
|
||||
assert_se( is_device_path("/sys/"));
|
||||
assert_se( is_device_path("/./sys"));
|
||||
assert_se( is_device_path("/./sys/."));
|
||||
assert_se(!is_device_path("/sys"));
|
||||
assert_se(!is_device_path("/sys/"));
|
||||
assert_se(!is_device_path("/./sys"));
|
||||
assert_se(!is_device_path("/./sys/."));
|
||||
assert_se(!is_device_path("/./sys."));
|
||||
assert_se( is_device_path("/./sys/foo"));
|
||||
assert_se( is_device_path("/./sys/./foo"));
|
||||
@@ -131,8 +131,8 @@ TEST(is_device_path) {
|
||||
assert_se( is_device_path("/sys/what"));
|
||||
assert_se( is_device_path("/sys/something/.."));
|
||||
assert_se( is_device_path("/sys/something/../"));
|
||||
assert_se( is_device_path("/sys////"));
|
||||
assert_se( is_device_path("/sys////."));
|
||||
assert_se(!is_device_path("/sys////"));
|
||||
assert_se(!is_device_path("/sys////."));
|
||||
assert_se( is_device_path("/sys/.."));
|
||||
assert_se( is_device_path("/sys/../"));
|
||||
assert_se(!is_device_path("/usr/../dev/sda"));
|
||||
|
||||
Reference in New Issue
Block a user