Apply vodz' last_patch52
[oweals/busybox.git] / libbb / remove_file.c
index 52b3211e652eb652eb4c5df2f04d71df8e33890f..988b09124add4f1eb1d1135ead88d7b1e7dc0abd 100644 (file)
@@ -2,10 +2,8 @@
 /*
  * Mini remove_file implementation for busybox
  *
- *
  * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
  *
- *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -19,7 +17,6 @@
  * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
  */
 
 #include <stdio.h>
@@ -29,6 +26,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <string.h>
 #include <getopt.h>
 #include "libbb.h"
 
@@ -37,7 +35,7 @@ extern int remove_file(const char *path, int flags)
        struct stat path_stat;
        int path_exists = 1;
 
-       if (stat(path, &path_stat) < 0) {
+       if (lstat(path, &path_stat) < 0) {
                if (errno != ENOENT) {
                        perror_msg("unable to stat `%s'", path);
                        return -1;
@@ -110,6 +108,7 @@ extern int remove_file(const char *path, int flags)
                return status;
        } else {
                if ((!(flags & FILEUTILS_FORCE) && access(path, W_OK) < 0 &&
+                                       !S_ISLNK(path_stat.st_mode) &&
                                        isatty(0)) ||
                                (flags & FILEUTILS_INTERACTIVE)) {
                        fprintf(stderr, "%s: remove `%s'? ", applet_name, path);