Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: runtime/bin/directory_win.cc

Issue 10916206: Fix for Directory.exists on Windows using GetFileAttributes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/directory.cc ('k') | tests/standalone/io/directory_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_win.cc
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
index 76044f137a536fb0636017c413d0df44ffdff1ed..08d502bbfe7b0cc8bdf98b085489c5e971ff5da2 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -222,6 +222,8 @@ static bool DeleteFile(char* file_name,
return DeleteFile(path) != 0;
}
}
+
+ return false;
}
@@ -318,29 +320,21 @@ bool Directory::List(const char* dir_name,
Directory::ExistsResult Directory::Exists(const char* dir_name) {
- struct stat entry_info;
- int stat_success = stat(dir_name, &entry_info);
- if (stat_success == 0) {
- if ((entry_info.st_mode & S_IFMT) == S_IFDIR) {
- return EXISTS;
- } else {
+ DWORD attributes = GetFileAttributes(dir_name);
+ if (attributes == INVALID_FILE_ATTRIBUTES) {
+ DWORD last_error = GetLastError();
+ if (last_error == ERROR_FILE_NOT_FOUND ||
+ last_error == ERROR_PATH_NOT_FOUND) {
return DOES_NOT_EXIST;
- }
- } else {
- if (errno == EACCES ||
- errno == EBADF ||
- errno == EFAULT ||
- errno == ENOMEM) {
- // 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.
+ } else {
+ // We might not be able to get the file attributes for other
+ // reasons such as lack of permissions. In that case we do
+ // not know if the directory exists.
return UNKNOWN;
}
- ASSERT(errno == ENAMETOOLONG ||
- errno == ENOENT ||
- errno == ENOTDIR);
- return DOES_NOT_EXIST;
}
+ bool exists = (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ return exists ? EXISTS : DOES_NOT_EXIST;
}
« no previous file with comments | « runtime/bin/directory.cc ('k') | tests/standalone/io/directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698