| Index: runtime/bin/directory_linux.cc
|
| diff --git a/runtime/bin/directory_linux.cc b/runtime/bin/directory_linux.cc
|
| index 2f2e6b0a5586e4fdcc518772b5fe23bb546a88c3..43ee54833aee95a4a4110d2f65280e853dc95515 100644
|
| --- a/runtime/bin/directory_linux.cc
|
| +++ b/runtime/bin/directory_linux.cc
|
| @@ -7,13 +7,13 @@
|
|
|
| #include "bin/directory.h"
|
|
|
| -#include <dirent.h> // NOLINT
|
| -#include <errno.h> // NOLINT
|
| -#include <stdlib.h> // NOLINT
|
| -#include <string.h> // NOLINT
|
| +#include <dirent.h> // NOLINT
|
| +#include <errno.h> // NOLINT
|
| +#include <stdlib.h> // NOLINT
|
| +#include <string.h> // NOLINT
|
| #include <sys/param.h> // NOLINT
|
| -#include <sys/stat.h> // NOLINT
|
| -#include <unistd.h> // NOLINT
|
| +#include <sys/stat.h> // NOLINT
|
| +#include <unistd.h> // NOLINT
|
|
|
| #include "bin/dartutils.h"
|
| #include "bin/file.h"
|
| @@ -57,13 +57,9 @@ const char* PathBuffer::AsScopedString() const {
|
|
|
| bool PathBuffer::Add(const char* name) {
|
| char* data = AsString();
|
| - int written = snprintf(data + length_,
|
| - PATH_MAX - length_,
|
| - "%s",
|
| - name);
|
| + int written = snprintf(data + length_, PATH_MAX - length_, "%s", name);
|
| data[PATH_MAX] = '\0';
|
| - if ((written <= PATH_MAX - length_) &&
|
| - (written >= 0) &&
|
| + if ((written <= PATH_MAX - length_) && (written >= 0) &&
|
| (static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1))) {
|
| length_ += written;
|
| return true;
|
| @@ -137,8 +133,8 @@ ListType DirectoryListingEntry::Next(DirectoryListing* listing) {
|
| if (!listing->follow_links()) {
|
| return kListLink;
|
| }
|
| - // Else fall through to next case.
|
| - // Fall through.
|
| + // Else fall through to next case.
|
| + // Fall through.
|
| case DT_UNKNOWN: {
|
| // On some file systems the entry type is not determined by
|
| // readdir. For those and for links we use stat to determine
|
| @@ -153,9 +149,7 @@ ListType DirectoryListingEntry::Next(DirectoryListing* listing) {
|
| }
|
| if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) {
|
| // Check to see if we are in a loop created by a symbolic link.
|
| - LinkList current_link = { entry_info.st_dev,
|
| - entry_info.st_ino,
|
| - link_ };
|
| + LinkList current_link = {entry_info.st_dev, entry_info.st_ino, link_};
|
| LinkList* previous = link_;
|
| while (previous != NULL) {
|
| if ((previous->dev == current_link.dev) &&
|
| @@ -231,15 +225,13 @@ void DirectoryListingEntry::ResetLink() {
|
| static bool DeleteRecursively(PathBuffer* path);
|
|
|
|
|
| -static bool DeleteFile(char* file_name,
|
| - PathBuffer* path) {
|
| +static bool DeleteFile(char* file_name, PathBuffer* path) {
|
| return path->Add(file_name) &&
|
| - (NO_RETRY_EXPECTED(unlink(path->AsString())) == 0);
|
| + (NO_RETRY_EXPECTED(unlink(path->AsString())) == 0);
|
| }
|
|
|
|
|
| -static bool DeleteDir(char* dir_name,
|
| - PathBuffer* path) {
|
| +static bool DeleteDir(char* dir_name, PathBuffer* path) {
|
| if ((strcmp(dir_name, ".") == 0) || (strcmp(dir_name, "..") == 0)) {
|
| return true;
|
| }
|
| @@ -273,24 +265,20 @@ static bool DeleteRecursively(PathBuffer* path) {
|
|
|
| // Iterate the directory and delete all files and directories.
|
| int path_length = path->length();
|
| - while (true){
|
| - // In case `readdir()` returns `NULL` we distinguish between end-of-stream and error
|
| - // by looking if `errno` was updated.
|
| + while (true) {
|
| + // In case `readdir()` returns `NULL` we distinguish between end-of-stream
|
| + // and error by looking if `errno` was updated.
|
| errno = 0;
|
| // In glibc 2.24+, readdir_r is deprecated.
|
| // According to the man page for readdir:
|
| // "readdir(3) is not required to be thread-safe. However, in modern
|
| // implementations (including the glibc implementation), concurrent calls to
|
| - // readdir(3) that specify different directory streams are thread-safe.
|
| - // Therefore, the use of readdir_r() is generally unnecessary in multithreaded
|
| - // programs. In cases where multiple threads must read from the same directory
|
| - // stream, using readdir(3) with external synchronization is still preferable
|
| - // to the use of readdir_r(), for the reasons given in the points above."
|
| + // readdir(3) that specify different directory streams are thread-safe."
|
| dirent* entry = readdir(dir_pointer);
|
| if (entry == NULL) {
|
| // Failed to read next directory entry.
|
| if (errno != 0) {
|
| - break;
|
| + break;
|
| }
|
| // End of directory.
|
| return (NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0) &&
|
| @@ -357,19 +345,14 @@ Directory::ExistsResult Directory::Exists(const char* dir_name) {
|
| return DOES_NOT_EXIST;
|
| }
|
| } else {
|
| - if ((errno == EACCES) ||
|
| - (errno == EBADF) ||
|
| - (errno == EFAULT) ||
|
| - (errno == ENOMEM) ||
|
| - (errno == EOVERFLOW)) {
|
| + if ((errno == EACCES) || (errno == EBADF) || (errno == EFAULT) ||
|
| + (errno == ENOMEM) || (errno == EOVERFLOW)) {
|
| // Search permissions denied for one of the directories in the
|
| // path or a low level error occured. We do not know if the
|
| // directory exists.
|
| return UNKNOWN;
|
| }
|
| - ASSERT((errno == ELOOP) ||
|
| - (errno == ENAMETOOLONG) ||
|
| - (errno == ENOENT) ||
|
| + ASSERT((errno == ELOOP) || (errno == ENAMETOOLONG) || (errno == ENOENT) ||
|
| (errno == ENOTDIR));
|
| return DOES_NOT_EXIST;
|
| }
|
|
|