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

Side by Side Diff: base/files/file_posix.cc

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/files/file_path.cc ('k') | base/files/file_tracing.h » ('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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file.h" 5 #include "base/files/file.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 CHECK_EQ(file_memory_checksum_, computed_checksum) << "corrupted fd memory"; 459 CHECK_EQ(file_memory_checksum_, computed_checksum) << "corrupted fd memory";
460 } 460 }
461 461
462 void File::MemoryCheckingScopedFD::UpdateChecksum() { 462 void File::MemoryCheckingScopedFD::UpdateChecksum() {
463 ComputeMemoryChecksum(&file_memory_checksum_); 463 ComputeMemoryChecksum(&file_memory_checksum_);
464 } 464 }
465 465
466 // NaCl doesn't implement system calls to open files directly. 466 // NaCl doesn't implement system calls to open files directly.
467 #if !defined(OS_NACL) 467 #if !defined(OS_NACL)
468 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? 468 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here?
469 void File::DoInitialize(uint32 flags) { 469 void File::DoInitialize(const FilePath& path, uint32 flags) {
470 ThreadRestrictions::AssertIOAllowed(); 470 ThreadRestrictions::AssertIOAllowed();
471 DCHECK(!IsValid()); 471 DCHECK(!IsValid());
472 472
473 int open_flags = 0; 473 int open_flags = 0;
474 if (flags & FLAG_CREATE) 474 if (flags & FLAG_CREATE)
475 open_flags = O_CREAT | O_EXCL; 475 open_flags = O_CREAT | O_EXCL;
476 476
477 created_ = false; 477 created_ = false;
478 478
479 if (flags & FLAG_CREATE_ALWAYS) { 479 if (flags & FLAG_CREATE_ALWAYS) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 else if (flags & FLAG_APPEND) 514 else if (flags & FLAG_APPEND)
515 open_flags |= O_APPEND | O_WRONLY; 515 open_flags |= O_APPEND | O_WRONLY;
516 516
517 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); 517 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero);
518 518
519 int mode = S_IRUSR | S_IWUSR; 519 int mode = S_IRUSR | S_IWUSR;
520 #if defined(OS_CHROMEOS) 520 #if defined(OS_CHROMEOS)
521 mode |= S_IRGRP | S_IROTH; 521 mode |= S_IRGRP | S_IROTH;
522 #endif 522 #endif
523 523
524 int descriptor = HANDLE_EINTR(open(path_.value().c_str(), open_flags, mode)); 524 int descriptor = HANDLE_EINTR(open(path.value().c_str(), open_flags, mode));
525 525
526 if (flags & FLAG_OPEN_ALWAYS) { 526 if (flags & FLAG_OPEN_ALWAYS) {
527 if (descriptor < 0) { 527 if (descriptor < 0) {
528 open_flags |= O_CREAT; 528 open_flags |= O_CREAT;
529 if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE) 529 if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE)
530 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW 530 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW
531 531
532 descriptor = HANDLE_EINTR(open(path_.value().c_str(), open_flags, mode)); 532 descriptor = HANDLE_EINTR(open(path.value().c_str(), open_flags, mode));
533 if (descriptor >= 0) 533 if (descriptor >= 0)
534 created_ = true; 534 created_ = true;
535 } 535 }
536 } 536 }
537 537
538 if (descriptor < 0) { 538 if (descriptor < 0) {
539 error_details_ = File::OSErrorToFileError(errno); 539 error_details_ = File::OSErrorToFileError(errno);
540 return; 540 return;
541 } 541 }
542 542
543 if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) 543 if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE))
544 created_ = true; 544 created_ = true;
545 545
546 if (flags & FLAG_DELETE_ON_CLOSE) 546 if (flags & FLAG_DELETE_ON_CLOSE)
547 unlink(path_.value().c_str()); 547 unlink(path.value().c_str());
548 548
549 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); 549 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC);
550 error_details_ = FILE_OK; 550 error_details_ = FILE_OK;
551 file_.reset(descriptor); 551 file_.reset(descriptor);
552 } 552 }
553 #endif // !defined(OS_NACL) 553 #endif // !defined(OS_NACL)
554 554
555 bool File::DoFlush() { 555 bool File::DoFlush() {
556 ThreadRestrictions::AssertIOAllowed(); 556 ThreadRestrictions::AssertIOAllowed();
557 DCHECK(IsValid()); 557 DCHECK(IsValid());
558 558
559 #if defined(OS_NACL) 559 #if defined(OS_NACL)
560 NOTIMPLEMENTED(); // NaCl doesn't implement fsync. 560 NOTIMPLEMENTED(); // NaCl doesn't implement fsync.
561 return true; 561 return true;
562 #elif defined(OS_LINUX) || defined(OS_ANDROID) 562 #elif defined(OS_LINUX) || defined(OS_ANDROID)
563 return !HANDLE_EINTR(fdatasync(file_.get())); 563 return !HANDLE_EINTR(fdatasync(file_.get()));
564 #else 564 #else
565 return !HANDLE_EINTR(fsync(file_.get())); 565 return !HANDLE_EINTR(fsync(file_.get()));
566 #endif 566 #endif
567 } 567 }
568 568
569 void File::SetPlatformFile(PlatformFile file) { 569 void File::SetPlatformFile(PlatformFile file) {
570 DCHECK(!file_.is_valid()); 570 DCHECK(!file_.is_valid());
571 file_.reset(file); 571 file_.reset(file);
572 } 572 }
573 573
574 } // namespace base 574 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path.cc ('k') | base/files/file_tracing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698