| 110 | Return true if successful. */ |
| 111 | |
| 112 | static bool |
| 113 | remove_parents (char *dir) |
| 114 | { |
| 115 | bool ok = true; |
| 116 | |
| 117 | strip_trailing_slashes (dir); |
| 118 | while (true) |
| 119 | { |
| 120 | char *slash = strrchr (dir, '/'); |
| 121 | if (slash == NULL) |
| 122 | break; |
| 123 | /* Remove any characters after the slash, skipping any extra |
| 124 | slashes in a row. */ |
| 125 | while (slash > dir && *slash == '/') |
| 126 | --slash; |
| 127 | slash[1] = 0; |
| 128 | |
| 129 | /* Give a diagnostic for each attempted removal if --verbose. */ |
| 130 | if (verbose) |
| 131 | prog_fprintf (stdout, _("removing directory, %s"), quoteaf (dir)); |
| 132 | |
| 133 | ok = (rmdir (dir) == 0); |
| 134 | int rmdir_errno = errno; |
| 135 | |
| 136 | if (! ok) |
| 137 | { |
| 138 | /* Stop quietly if --ignore-fail-on-non-empty. */ |
| 139 | if (ignorable_failure (rmdir_errno, dir)) |
| 140 | { |
| 141 | ok = true; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | char const *error_msg; |
| 146 | if (rmdir_errno != ENOTDIR) |
| 147 | { |
| 148 | /* Barring race conditions, |
| 149 | DIR is expected to be a directory. */ |
| 150 | error_msg = N_("failed to remove directory %s"); |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | /* A path component could be a symbolic link */ |
| 155 | error_msg = N_("failed to remove %s"); |
| 156 | } |
| 157 | error (0, rmdir_errno, _(error_msg), quoteaf (dir)); |
| 158 | } |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | return ok; |
| 163 | } |
| 164 | |
| 165 | void |
| 166 | usage (int status) |
no test coverage detected