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

Unified Diff: runtime/bin/file_android.cc

Issue 2593913003: Make File.create() fail when a directory exists at the same path (Closed)
Patch Set: Fix test for Windows Created 4 years 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 | « no previous file | runtime/bin/file_fuchsia.cc » ('j') | tests/standalone/io/file_create_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_android.cc
diff --git a/runtime/bin/file_android.cc b/runtime/bin/file_android.cc
index afe09669b9afce2d091c9518520c05aa5ecc496e..985fbf8cd9d13b97bacc3072c91e5e520c23387f 100644
--- a/runtime/bin/file_android.cc
+++ b/runtime/bin/file_android.cc
@@ -17,8 +17,8 @@
#include <unistd.h> // NOLINT
#include "bin/builtin.h"
+#include "bin/fdutils.h"
#include "bin/log.h"
-
#include "platform/signal_blocker.h"
#include "platform/utils.h"
@@ -227,7 +227,8 @@ File* File::OpenStdio(int fd) {
bool File::Exists(const char* name) {
struct stat st;
if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) {
- return S_ISREG(st.st_mode);
+ // Everything but a directory and a link is a file to Dart.
+ return !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode);
} else {
return false;
}
@@ -239,7 +240,22 @@ bool File::Create(const char* name) {
if (fd < 0) {
return false;
}
- return (close(fd) == 0);
+ // File.create returns a File, so we shouldn't be giving the illusion that the
+ // call has created a file or that a file already exists if there is already
+ // an entity at the same path that is a directory or a link.
+ bool is_file = true;
+ struct stat st;
+ if (NO_RETRY_EXPECTED(fstat(fd, &st)) == 0) {
+ if (S_ISDIR(st.st_mode)) {
+ errno = EISDIR;
+ is_file = false;
+ } else if (S_ISLNK(st.st_mode)) {
+ errno = ENOENT;
+ is_file = false;
+ }
+ }
+ FDUtils::SaveErrorAndClose(fd);
+ return is_file;
}
« no previous file with comments | « no previous file | runtime/bin/file_fuchsia.cc » ('j') | tests/standalone/io/file_create_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698