- dev = udevdb_get_dev(path);
- if (dev != NULL) {
- strcpy(name, dev->name);
- goto exit;
+ pos = strrchr(path, '/');
+ while (1) {
+ *pos = '\0';
+ pos = strrchr(path, '/');
+
+ /* don't remove the last one */
+ if ((pos == path) || (pos == NULL))
+ break;
+
+ /* remove if empty */
+ retval = rmdir(path);
+ if (retval) {
+ if (errno == ENOTEMPTY)
+ return 0;
+ dbg("rmdir(%s) failed with error '%s'",
+ path, strerror(errno));
+ break;
+ }
+ dbg("removed '%s'", path);