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

Side by Side Diff: runtime/bin/file_android.cc

Issue 2599723002: Revert "Make File.create() fail when a directory exists at the same path" (Closed)
Patch Set: Created 3 years, 12 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/file_fuchsia.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <fcntl.h> // NOLINT 11 #include <fcntl.h> // NOLINT
12 #include <libgen.h> // NOLINT 12 #include <libgen.h> // NOLINT
13 #include <sys/mman.h> // NOLINT 13 #include <sys/mman.h> // NOLINT
14 #include <sys/sendfile.h> // NOLINT 14 #include <sys/sendfile.h> // NOLINT
15 #include <sys/stat.h> // NOLINT 15 #include <sys/stat.h> // NOLINT
16 #include <sys/types.h> // NOLINT 16 #include <sys/types.h> // NOLINT
17 #include <unistd.h> // NOLINT 17 #include <unistd.h> // NOLINT
18 18
19 #include "bin/builtin.h" 19 #include "bin/builtin.h"
20 #include "bin/fdutils.h"
21 #include "bin/log.h" 20 #include "bin/log.h"
21
22 #include "platform/signal_blocker.h" 22 #include "platform/signal_blocker.h"
23 #include "platform/utils.h" 23 #include "platform/utils.h"
24 24
25 namespace dart { 25 namespace dart {
26 namespace bin { 26 namespace bin {
27 27
28 class FileHandle { 28 class FileHandle {
29 public: 29 public:
30 explicit FileHandle(int fd) : fd_(fd) {} 30 explicit FileHandle(int fd) : fd_(fd) {}
31 ~FileHandle() {} 31 ~FileHandle() {}
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 221
222 File* File::OpenStdio(int fd) { 222 File* File::OpenStdio(int fd) {
223 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd)); 223 return ((fd < 0) || (2 < fd)) ? NULL : new File(new FileHandle(fd));
224 } 224 }
225 225
226 226
227 bool File::Exists(const char* name) { 227 bool File::Exists(const char* name) {
228 struct stat st; 228 struct stat st;
229 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { 229 if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) {
230 // Everything but a directory and a link is a file to Dart. 230 return S_ISREG(st.st_mode);
231 return !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode);
232 } else { 231 } else {
233 return false; 232 return false;
234 } 233 }
235 } 234 }
236 235
237 236
238 bool File::Create(const char* name) { 237 bool File::Create(const char* name) {
239 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666)); 238 int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
240 if (fd < 0) { 239 if (fd < 0) {
241 return false; 240 return false;
242 } 241 }
243 // File.create returns a File, so we shouldn't be giving the illusion that the 242 return (close(fd) == 0);
244 // call has created a file or that a file already exists if there is already
245 // an entity at the same path that is a directory or a link.
246 bool is_file = true;
247 struct stat st;
248 if (NO_RETRY_EXPECTED(fstat(fd, &st)) == 0) {
249 if (S_ISDIR(st.st_mode)) {
250 errno = EISDIR;
251 is_file = false;
252 } else if (S_ISLNK(st.st_mode)) {
253 errno = ENOENT;
254 is_file = false;
255 }
256 }
257 FDUtils::SaveErrorAndClose(fd);
258 return is_file;
259 } 243 }
260 244
261 245
262 bool File::CreateLink(const char* name, const char* target) { 246 bool File::CreateLink(const char* name, const char* target) {
263 int status = NO_RETRY_EXPECTED(symlink(target, name)); 247 int status = NO_RETRY_EXPECTED(symlink(target, name));
264 return (status == 0); 248 return (status == 0);
265 } 249 }
266 250
267 251
268 bool File::Delete(const char* name) { 252 bool File::Delete(const char* name) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 return ((file_1_info.st_ino == file_2_info.st_ino) && 506 return ((file_1_info.st_ino == file_2_info.st_ino) &&
523 (file_1_info.st_dev == file_2_info.st_dev)) 507 (file_1_info.st_dev == file_2_info.st_dev))
524 ? File::kIdentical 508 ? File::kIdentical
525 : File::kDifferent; 509 : File::kDifferent;
526 } 510 }
527 511
528 } // namespace bin 512 } // namespace bin
529 } // namespace dart 513 } // namespace dart
530 514
531 #endif // defined(TARGET_OS_ANDROID) 515 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/file_fuchsia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698