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 const time_t last_modified_sec = file_info.st_mtime; | |
darin (slow to review)
2013/08/07 18:17:28
should there be a TODO here to investigate the bes
gavinp
2013/08/07 18:24:39
Done.
| |
406 const int64 last_modified_nsec = 0; | |
407 const time_t last_accessed_sec = file_info.st_atime; | |
408 const int64 last_accessed_nsec = 0; | |
409 const time_t creation_time_sec = file_info.st_ctime; | |
410 const int64 creation_time_nsec = 0; | |
411 #endif | |
412 | |
413 info->last_modified = | |
414 base::Time::FromTimeT(last_modified_sec) + | |
415 base::TimeDelta::FromMicroseconds(last_modified_nsec / | |
416 base::Time::kNanosecondsPerMicrosecond); | |
417 info->last_accessed = | |
418 base::Time::FromTimeT(last_accessed_sec) + | |
419 base::TimeDelta::FromMicroseconds(last_accessed_nsec / | |
420 base::Time::kNanosecondsPerMicrosecond); | |
421 info->creation_time = | |
422 base::Time::FromTimeT(creation_time_sec) + | |
423 base::TimeDelta::FromMicroseconds(creation_time_nsec / | |
424 base::Time::kNanosecondsPerMicrosecond); | |
385 return true; | 425 return true; |
386 } | 426 } |
387 | 427 |
388 PlatformFileError ErrnoToPlatformFileError(int saved_errno) { | 428 PlatformFileError ErrnoToPlatformFileError(int saved_errno) { |
389 switch (saved_errno) { | 429 switch (saved_errno) { |
390 case EACCES: | 430 case EACCES: |
391 case EISDIR: | 431 case EISDIR: |
392 case EROFS: | 432 case EROFS: |
393 case EPERM: | 433 case EPERM: |
394 return PLATFORM_FILE_ERROR_ACCESS_DENIED; | 434 return PLATFORM_FILE_ERROR_ACCESS_DENIED; |
(...skipping 16 matching lines...) Expand all Loading... | |
411 default: | 451 default: |
412 #if !defined(OS_NACL) // NaCl build has no metrics code. | 452 #if !defined(OS_NACL) // NaCl build has no metrics code. |
413 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", | 453 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", |
414 saved_errno); | 454 saved_errno); |
415 #endif | 455 #endif |
416 return PLATFORM_FILE_ERROR_FAILED; | 456 return PLATFORM_FILE_ERROR_FAILED; |
417 } | 457 } |
418 } | 458 } |
419 | 459 |
420 } // namespace base | 460 } // namespace base |
OLD | NEW |