X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_utils_file.c;h=9bf60696d94ed74d9ddd79d5b854e918154dc1c2;hp=f8518f64ade113b7df2f919e5bd6da161c3b2516;hb=1bcfb137e838a9fa8c607aa2e88b1b1f0716f296;hpb=59d6bfefceac1a31b0408e60cd251b5035cf3b50 diff --git a/udev_utils_file.c b/udev_utils_file.c index f8518f64a..9bf60696d 100644 --- a/udev_utils_file.c +++ b/udev_utils_file.c @@ -1,6 +1,4 @@ /* - * udev_utils_file.c - files operations - * * Copyright (C) 2004-2005 Kay Sievers * * This program is free software; you can redistribute it and/or modify it @@ -14,7 +12,7 @@ * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., - * 675 Mass Ave, Cambridge, MA 02139, USA. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ @@ -30,11 +28,7 @@ #include #include -#include "udev_libc_wrapper.h" #include "udev.h" -#include "logging.h" -#include "udev_utils.h" -#include "list.h" int create_path(const char *path) { @@ -53,7 +47,7 @@ int create_path(const char *path) pos[0] = '\0'; dbg("stat '%s'\n", p); - if (stat (p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) + if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) return 0; if (create_path (p) != 0) @@ -63,6 +57,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. */ @@ -72,18 +97,18 @@ int unlink_secure(const char *filename) retval = chown(filename, 0, 0); if (retval) - dbg("chown(%s, 0, 0) failed with error '%s'", filename, strerror(errno)); + err("chown(%s, 0, 0) failed: %s", filename, strerror(errno)); retval = chmod(filename, 0000); if (retval) - dbg("chmod(%s, 0000) failed with error '%s'", filename, strerror(errno)); + err("chmod(%s, 0000) failed: %s", filename, strerror(errno)); retval = unlink(filename); if (errno == ENOENT) retval = 0; if (retval) - dbg("unlink(%s) failed with error '%s'", filename, strerror(errno)); + err("unlink(%s) failed: %s", filename, strerror(errno)); return retval; }