OLD | NEW |
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/platform_file.h" | 5 #include "base/platform_file.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 if (!info) | 372 if (!info) |
373 return false; | 373 return false; |
374 | 374 |
375 stat_wrapper_t file_info; | 375 stat_wrapper_t file_info; |
376 if (CallFstat(file, &file_info)) | 376 if (CallFstat(file, &file_info)) |
377 return false; | 377 return false; |
378 | 378 |
379 info->is_directory = S_ISDIR(file_info.st_mode); | 379 info->is_directory = S_ISDIR(file_info.st_mode); |
380 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 380 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
381 info->size = file_info.st_size; | 381 info->size = file_info.st_size; |
382 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 382 |
383 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 383 #if defined(OS_LINUX) |
384 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 384 const time_t last_modified_sec = file_info.st_mtim.tv_sec; |
| 385 const int64 last_modified_nsec = file_info.st_mtim.tv_nsec; |
| 386 const time_t last_accessed_sec = file_info.st_atim.tv_sec; |
| 387 const int64 last_accessed_nsec = file_info.st_atim.tv_nsec; |
| 388 const time_t creation_time_sec = file_info.st_ctim.tv_sec; |
| 389 const int64 creation_time_nsec = file_info.st_ctim.tv_nsec; |
| 390 #elif defined(OS_ANDROID) |
| 391 const time_t last_modified_sec = file_info.st_mtime; |
| 392 const int64 last_modified_nsec = file_info.st_mtime_nsec; |
| 393 const time_t last_accessed_sec = file_info.st_atime; |
| 394 const int64 last_accessed_nsec = file_info.st_atime_nsec; |
| 395 const time_t creation_time_sec = file_info.st_ctime; |
| 396 const int64 creation_time_nsec = file_info.st_ctime_nsec; |
| 397 #elif defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_BSD) |
| 398 const time_t last_modified_sec = file_info.st_mtimespec.tv_sec; |
| 399 const int64 last_modified_nsec = file_info.st_mtimespec.tv_nsec; |
| 400 const time_t last_accessed_sec = file_info.st_atimespec.tv_sec; |
| 401 const int64 last_accessed_nsec = file_info.st_atimespec.tv_nsec; |
| 402 const time_t creation_time_sec = file_info.st_ctimespec.tv_sec; |
| 403 const int64 creation_time_nsec = file_info.st_ctimespec.tv_nsec; |
| 404 #else |
| 405 // TODO(gavinp): Investigate a good high resolution option for OS_NACL. |
| 406 const time_t last_modified_sec = file_info.st_mtime; |
| 407 const int64 last_modified_nsec = 0; |
| 408 const time_t last_accessed_sec = file_info.st_atime; |
| 409 const int64 last_accessed_nsec = 0; |
| 410 const time_t creation_time_sec = file_info.st_ctime; |
| 411 const int64 creation_time_nsec = 0; |
| 412 #endif |
| 413 |
| 414 info->last_modified = |
| 415 base::Time::FromTimeT(last_modified_sec) + |
| 416 base::TimeDelta::FromMicroseconds(last_modified_nsec / |
| 417 base::Time::kNanosecondsPerMicrosecond); |
| 418 info->last_accessed = |
| 419 base::Time::FromTimeT(last_accessed_sec) + |
| 420 base::TimeDelta::FromMicroseconds(last_accessed_nsec / |
| 421 base::Time::kNanosecondsPerMicrosecond); |
| 422 info->creation_time = |
| 423 base::Time::FromTimeT(creation_time_sec) + |
| 424 base::TimeDelta::FromMicroseconds(creation_time_nsec / |
| 425 base::Time::kNanosecondsPerMicrosecond); |
385 return true; | 426 return true; |
386 } | 427 } |
387 | 428 |
388 PlatformFileError ErrnoToPlatformFileError(int saved_errno) { | 429 PlatformFileError ErrnoToPlatformFileError(int saved_errno) { |
389 switch (saved_errno) { | 430 switch (saved_errno) { |
390 case EACCES: | 431 case EACCES: |
391 case EISDIR: | 432 case EISDIR: |
392 case EROFS: | 433 case EROFS: |
393 case EPERM: | 434 case EPERM: |
394 return PLATFORM_FILE_ERROR_ACCESS_DENIED; | 435 return PLATFORM_FILE_ERROR_ACCESS_DENIED; |
(...skipping 16 matching lines...) Expand all Loading... |
411 default: | 452 default: |
412 #if !defined(OS_NACL) // NaCl build has no metrics code. | 453 #if !defined(OS_NACL) // NaCl build has no metrics code. |
413 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", | 454 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", |
414 saved_errno); | 455 saved_errno); |
415 #endif | 456 #endif |
416 return PLATFORM_FILE_ERROR_FAILED; | 457 return PLATFORM_FILE_ERROR_FAILED; |
417 } | 458 } |
418 } | 459 } |
419 | 460 |
420 } // namespace base | 461 } // namespace base |
OLD | NEW |