summaryrefslogtreecommitdiffstats
path: root/otautil/DirUtil.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-07-25 16:38:52 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-07-25 16:38:52 +0200
commite3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3 (patch)
treecff74e879b13d5d0f7478ac14645ab68efa23b4f /otautil/DirUtil.cpp
parentMerge "roots.cpp: Reformatting the file." am: ac70ffcc85 am: 922a310d36 am: bba1e66f74 (diff)
parentMerge "otautil: Delete dirUnlinkHierarchy()." am: 031661d4a9 am: 993cec5cc9 (diff)
downloadandroid_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.tar
android_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.tar.gz
android_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.tar.bz2
android_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.tar.lz
android_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.tar.xz
android_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.tar.zst
android_bootable_recovery-e3134ff774e6d35bb84f8f40ca3d64e2eef6a0e3.zip
Diffstat (limited to '')
-rw-r--r--otautil/DirUtil.cpp56
1 files changed, 0 insertions, 56 deletions
diff --git a/otautil/DirUtil.cpp b/otautil/DirUtil.cpp
index e08e360c0..ad344dedf 100644
--- a/otautil/DirUtil.cpp
+++ b/otautil/DirUtil.cpp
@@ -160,59 +160,3 @@ dirCreateHierarchy(const char *path, int mode,
}
return 0;
}
-
-int
-dirUnlinkHierarchy(const char *path)
-{
- struct stat st;
- DIR *dir;
- struct dirent *de;
- int fail = 0;
-
- /* is it a file or directory? */
- if (lstat(path, &st) < 0) {
- return -1;
- }
-
- /* a file, so unlink it */
- if (!S_ISDIR(st.st_mode)) {
- return unlink(path);
- }
-
- /* a directory, so open handle */
- dir = opendir(path);
- if (dir == NULL) {
- return -1;
- }
-
- /* recurse over components */
- errno = 0;
- while ((de = readdir(dir)) != NULL) {
- //TODO: don't blow the stack
- char dn[PATH_MAX];
- if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) {
- continue;
- }
- snprintf(dn, sizeof(dn), "%s/%s", path, de->d_name);
- if (dirUnlinkHierarchy(dn) < 0) {
- fail = 1;
- break;
- }
- errno = 0;
- }
- /* in case readdir or unlink_recursive failed */
- if (fail || errno < 0) {
- int save = errno;
- closedir(dir);
- errno = save;
- return -1;
- }
-
- /* close directory handle */
- if (closedir(dir) < 0) {
- return -1;
- }
-
- /* delete target directory */
- return rmdir(path);
-}