diff --git a/coreutils/rm.c b/coreutils/rm.c index 2100754..fb87234 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -7,7 +7,7 @@ #include int get_stat(const char *path, struct stat *stat_path) { - if (stat(path, stat_path)) { + if (lstat(path, stat_path)) { fprintf(stderr, "rm: unable to stat %s: %s\n", path, strerror(errno)); return 1; } @@ -17,9 +17,10 @@ int get_stat(const char *path, struct stat *stat_path) { int rmtree(const char *path) { struct stat stat_path; - get_stat(path, &stat_path); + if (get_stat(path, &stat_path)) + return 1; - if (S_ISDIR(stat_path.st_mode) == 0) { + if (!S_ISDIR(stat_path.st_mode) || S_ISLNK(stat_path.st_mode)) { if (unlink(path) < 0) { fprintf(stderr, "rm: %s: is not directory\n", path); return 1;