OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 // Mkdir failed, but it might have failed with EEXIST, or some other error | 515 // Mkdir failed, but it might have failed with EEXIST, or some other error |
516 // due to the the directory appearing out of thin air. This can occur if | 516 // due to the the directory appearing out of thin air. This can occur if |
517 // two processes are trying to create the same file system tree at the same | 517 // two processes are trying to create the same file system tree at the same |
518 // time. Check to see if it exists and make sure it is a directory. | 518 // time. Check to see if it exists and make sure it is a directory. |
519 if (!DirectoryExists(*i)) | 519 if (!DirectoryExists(*i)) |
520 return false; | 520 return false; |
521 } | 521 } |
522 return true; | 522 return true; |
523 } | 523 } |
524 | 524 |
| 525 #if defined(OS_CHROMEOS) |
| 526 // TODO(rkc): Refactor GetFileInfo and FileEnumerator to handle symlinks |
| 527 // correctly; this is just a hack to fix symlink handling for now for ChromeOS |
| 528 bool IsLink(const FilePath& file_path) { |
| 529 struct stat st; |
| 530 // If we can't lstat the file, it's safe to assume that the file won't at |
| 531 // least be a 'followable' link |
| 532 if (lstat(file_path.value().c_str(), &st) != 0) |
| 533 return false; |
| 534 |
| 535 if (S_ISLNK(st.st_mode)) |
| 536 return true; |
| 537 else |
| 538 return false; |
| 539 } |
| 540 #endif |
| 541 |
525 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { | 542 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { |
526 stat_wrapper_t file_info; | 543 stat_wrapper_t file_info; |
527 if (CallStat(file_path.value().c_str(), &file_info) != 0) | 544 if (CallStat(file_path.value().c_str(), &file_info) != 0) |
528 return false; | 545 return false; |
529 results->is_directory = S_ISDIR(file_info.st_mode); | 546 results->is_directory = S_ISDIR(file_info.st_mode); |
530 results->size = file_info.st_size; | 547 results->size = file_info.st_size; |
531 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 548 results->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
532 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 549 results->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
533 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 550 results->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
534 return true; | 551 return true; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 if (HANDLE_EINTR(close(infile)) < 0) | 912 if (HANDLE_EINTR(close(infile)) < 0) |
896 result = false; | 913 result = false; |
897 if (HANDLE_EINTR(close(outfile)) < 0) | 914 if (HANDLE_EINTR(close(outfile)) < 0) |
898 result = false; | 915 result = false; |
899 | 916 |
900 return result; | 917 return result; |
901 } | 918 } |
902 #endif // defined(OS_MACOSX) | 919 #endif // defined(OS_MACOSX) |
903 | 920 |
904 } // namespace file_util | 921 } // namespace file_util |
OLD | NEW |