move delete_path() to utils

This commit is contained in:
Scott James Remnant 2005-11-22 15:44:02 +01:00 committed by Kay Sievers
parent cfd0fc6605
commit 0da0efb2b6
3 changed files with 32 additions and 29 deletions

View File

@ -34,35 +34,6 @@
#include "udev_version.h"
#include "logging.h"
static int delete_path(const char *path)
{
char *pos;
int retval;
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 (errno == ENOENT)
retval = 0;
if (retval) {
if (errno == ENOTEMPTY)
return 0;
err("rmdir(%s) failed: %s", path, strerror(errno));
break;
}
dbg("removed '%s'", path);
}
return 0;
}
static int delete_node(struct udevice *udev)
{
char filename[PATH_SIZE];

View File

@ -51,6 +51,7 @@ extern int replace_untrusted_chars(char *str);
/* udev_utils_file.c */
extern int create_path(const char *path);
extern int delete_path(const char *path);
extern int file_map(const char *filename, char **buf, size_t *bufsize);
extern void file_unmap(void *buf, size_t bufsize);
extern int unlink_secure(const char *filename);

View File

@ -63,6 +63,37 @@ int create_path(const char *path)
return mkdir(p, 0755);
}
int delete_path(const char *path)
{
char p[PATH_SIZE];
char *pos;
int retval;
strcpy (p, path);
pos = strrchr(p, '/');
while (1) {
*pos = '\0';
pos = strrchr(p, '/');
/* don't remove the last one */
if ((pos == p) || (pos == NULL))
break;
/* remove if empty */
retval = rmdir(p);
if (errno == ENOENT)
retval = 0;
if (retval) {
if (errno == ENOTEMPTY)
return 0;
err("rmdir(%s) failed: %s", p, strerror(errno));
break;
}
dbg("removed '%s'", p);
}
return 0;
}
/* Reset permissions on the device node, before unlinking it to make sure,
* that permisions of possible hard links will be removed too.
*/