Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/remove_file.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/remove_file.c
r821 r1770 8 8 */ 9 9 10 #include <stdio.h>11 #include <time.h>12 #include <utime.h>13 #include <dirent.h>14 #include <errno.h>15 #include <unistd.h>16 #include <stdlib.h>17 #include <string.h>18 #include <getopt.h>19 10 #include "libbb.h" 11 12 /* Used from NOFORK applets. Must not allocate anything */ 20 13 21 14 int remove_file(const char *path, int flags) 22 15 { 23 16 struct stat path_stat; 24 int path_exists = 1;25 17 26 18 if (lstat(path, &path_stat) < 0) { 27 19 if (errno != ENOENT) { 28 bb_perror_msg(" unable to stat `%s'", path);20 bb_perror_msg("cannot stat '%s'", path); 29 21 return -1; 30 22 } 31 32 path_exists = 0;33 }34 35 if (!path_exists) {36 23 if (!(flags & FILEUTILS_FORCE)) { 37 bb_perror_msg("cannot remove `%s'", path);24 bb_perror_msg("cannot remove '%s'", path); 38 25 return -1; 39 26 } … … 51 38 } 52 39 53 if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 && 54 isatty(0)) ||55 (flags & FILEUTILS_INTERACTIVE)) {56 fprintf(stderr, "%s: descend into directory `%s'? ", bb_applet_name,40 if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 && isatty(0)) 41 || (flags & FILEUTILS_INTERACTIVE) 42 ) { 43 fprintf(stderr, "%s: descend into directory '%s'? ", applet_name, 57 44 path); 58 45 if (!bb_ask_confirmation()) … … 60 47 } 61 48 62 if ((dp = bb_opendir(path)) == NULL) { 49 dp = opendir(path); 50 if (dp == NULL) { 63 51 return -1; 64 52 } … … 68 56 69 57 new_path = concat_subpath_file(path, d->d_name); 70 if (new_path == NULL)58 if (new_path == NULL) 71 59 continue; 72 60 if (remove_file(new_path, flags) < 0) … … 76 64 77 65 if (closedir(dp) < 0) { 78 bb_perror_msg(" unable to close `%s'", path);66 bb_perror_msg("cannot close '%s'", path); 79 67 return -1; 80 68 } 81 69 82 70 if (flags & FILEUTILS_INTERACTIVE) { 83 fprintf(stderr, "%s: remove directory `%s'? ", bb_applet_name, path);71 fprintf(stderr, "%s: remove directory '%s'? ", applet_name, path); 84 72 if (!bb_ask_confirmation()) 85 73 return status; … … 87 75 88 76 if (rmdir(path) < 0) { 89 bb_perror_msg(" unable to remove `%s'", path);77 bb_perror_msg("cannot remove '%s'", path); 90 78 return -1; 91 79 } 92 80 93 81 return status; 94 } else { 95 if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 && 96 !S_ISLNK(path_stat.st_mode) && 97 isatty(0)) || 98 (flags & FILEUTILS_INTERACTIVE)) { 99 fprintf(stderr, "%s: remove `%s'? ", bb_applet_name, path); 100 if (!bb_ask_confirmation()) 101 return 0; 102 } 82 } 103 83 104 if (unlink(path) < 0) { 105 bb_perror_msg("unable to remove `%s'", path); 106 return -1; 107 } 84 /* !ISDIR */ 85 if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 86 && !S_ISLNK(path_stat.st_mode) && isatty(0)) 87 || (flags & FILEUTILS_INTERACTIVE) 88 ) { 89 fprintf(stderr, "%s: remove '%s'? ", applet_name, path); 90 if (!bb_ask_confirmation()) 91 return 0; 92 } 108 93 109 return 0; 94 if (unlink(path) < 0) { 95 bb_perror_msg("cannot remove '%s'", path); 96 return -1; 110 97 } 98 99 return 0; 111 100 }
Note:
See TracChangeset
for help on using the changeset viewer.