X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudevadm-info.c;h=4510f4aa907dc56a22544564ec1e10045046bf61;hb=48a0170b111b55e961be769d2cc4890511bcd991;hp=7206f4fcf621ed8f3c32cf35ed78d221b3b44a2e;hpb=4281da1fa6fda10c15bee984825fc607a8385004;p=elogind.git diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c index 7206f4fcf..4510f4aa9 100644 --- a/udev/udevadm-info.c +++ b/udev/udevadm-info.c @@ -210,38 +210,44 @@ static int convert_db(struct udev *udev) device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); if (device != NULL) { const char *id; - struct stat statbuf; + struct stat stats; char to[UTIL_PATH_SIZE]; char devpath[UTIL_PATH_SIZE]; char from[UTIL_PATH_SIZE]; id = udev_device_get_id_filename(device); - if (id == NULL) - goto next; + if (id == NULL) { + udev_device_unref(device); + continue; + } util_strscpyl(to, sizeof(to), udev_get_dev_path(udev), "/.udev/db/", id, NULL); - /* do not overwrite a new database file */ - if (lstat(to, &statbuf) == 0) - goto next; - /* find old database with $subsys:$sysname */ util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL); - if (lstat(from, &statbuf) == 0) { - rename(from, to); - goto next; + if (lstat(from, &stats) == 0) { + if (lstat(to, &stats) == 0) + unlink(from); + else + rename(from, to); } /* find old database with the encoded devpath */ util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath)); util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", devpath, NULL); - if (lstat(from, &statbuf) == 0) { - rename(from, to); - goto next; + if (lstat(from, &stats) == 0) { + if (lstat(to, &stats) == 0) + unlink(from); + else + rename(from, to); } -next: + + /* read the old database, and write out a new one */ + udev_device_read_db(device); + udev_device_update_db(device); + udev_device_unref(device); } }