| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <fnmatch.h> | 10 #include <fnmatch.h> |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 if (CallStat(file_path.value().c_str(), &file_info) != 0) | 517 if (CallStat(file_path.value().c_str(), &file_info) != 0) |
| 518 return false; | 518 return false; |
| 519 results->is_directory = S_ISDIR(file_info.st_mode); | 519 results->is_directory = S_ISDIR(file_info.st_mode); |
| 520 results->size = file_info.st_size; | 520 results->size = file_info.st_size; |
| 521 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 521 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
| 522 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 522 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
| 523 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 523 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
| 524 return true; | 524 return true; |
| 525 } | 525 } |
| 526 | 526 |
| 527 bool GetInode(const FilePath& path, ino_t* inode) { | 527 bool AreReferringToSameObject(const FilePath& a, const FilePath& b) { |
| 528 ino_t inode_a, inode_b; |
| 529 dev_t dev_a, dev_b; |
| 530 if (GetInodeAndDevice(a, &inode_a, &dev_a)) { |
| 531 if (GetInodeAndDevice(b, &inode_b, &dev_b)) { |
| 532 return (inode_a == inode_b) && (dev_a == dev_b); |
| 533 } |
| 534 } |
| 535 return false; |
| 536 } |
| 537 |
| 538 bool GetInodeAndDevice(const FilePath& path, ino_t* inode, dev_t* dev) { |
| 528 base::ThreadRestrictions::AssertIOAllowed(); // For call to stat(). | 539 base::ThreadRestrictions::AssertIOAllowed(); // For call to stat(). |
| 529 struct stat buffer; | 540 struct stat buffer; |
| 530 int result = stat(path.value().c_str(), &buffer); | 541 int result = stat(path.value().c_str(), &buffer); |
| 531 if (result < 0) | 542 if (result < 0) |
| 532 return false; | 543 return false; |
| 533 | 544 |
| 545 *dev = buffer.st_dev; |
| 534 *inode = buffer.st_ino; | 546 *inode = buffer.st_ino; |
| 535 return true; | 547 return true; |
| 536 } | 548 } |
| 537 | 549 |
| 538 FILE* OpenFile(const std::string& filename, const char* mode) { | 550 FILE* OpenFile(const std::string& filename, const char* mode) { |
| 539 return OpenFile(FilePath(filename), mode); | 551 return OpenFile(FilePath(filename), mode); |
| 540 } | 552 } |
| 541 | 553 |
| 542 FILE* OpenFile(const FilePath& filename, const char* mode) { | 554 FILE* OpenFile(const FilePath& filename, const char* mode) { |
| 543 base::ThreadRestrictions::AssertIOAllowed(); | 555 base::ThreadRestrictions::AssertIOAllowed(); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 if (HANDLE_EINTR(close(infile)) < 0) | 893 if (HANDLE_EINTR(close(infile)) < 0) |
| 882 result = false; | 894 result = false; |
| 883 if (HANDLE_EINTR(close(outfile)) < 0) | 895 if (HANDLE_EINTR(close(outfile)) < 0) |
| 884 result = false; | 896 result = false; |
| 885 | 897 |
| 886 return result; | 898 return result; |
| 887 } | 899 } |
| 888 #endif // defined(OS_MACOSX) | 900 #endif // defined(OS_MACOSX) |
| 889 | 901 |
| 890 } // namespace file_util | 902 } // namespace file_util |
| OLD | NEW |