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 <windows.h> | 7 #include <windows.h> |
8 #include <propvarutil.h> | 8 #include <propvarutil.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 ScopedHandle file(CreateFile(filename.value().c_str(), | 640 ScopedHandle file(CreateFile(filename.value().c_str(), |
641 GENERIC_READ, | 641 GENERIC_READ, |
642 FILE_SHARE_READ | FILE_SHARE_WRITE, | 642 FILE_SHARE_READ | FILE_SHARE_WRITE, |
643 NULL, | 643 NULL, |
644 OPEN_EXISTING, | 644 OPEN_EXISTING, |
645 FILE_FLAG_SEQUENTIAL_SCAN, | 645 FILE_FLAG_SEQUENTIAL_SCAN, |
646 NULL)); | 646 NULL)); |
647 if (file == INVALID_HANDLE_VALUE) | 647 if (file == INVALID_HANDLE_VALUE) |
648 return -1; | 648 return -1; |
649 | 649 |
650 int ret_value; | |
651 DWORD read; | 650 DWORD read; |
652 if (::ReadFile(file, data, size, &read, NULL) && read == size) { | 651 if (::ReadFile(file, data, size, &read, NULL) && |
653 ret_value = static_cast<int>(read); | 652 static_cast<int>(read) == size) |
654 } else { | 653 return read; |
655 ret_value = -1; | 654 return -1; |
656 } | |
657 | |
658 return ret_value; | |
659 } | 655 } |
660 | 656 |
661 int WriteFile(const FilePath& filename, const char* data, int size) { | 657 int WriteFile(const FilePath& filename, const char* data, int size) { |
662 ScopedHandle file(CreateFile(filename.value().c_str(), | 658 ScopedHandle file(CreateFile(filename.value().c_str(), |
663 GENERIC_WRITE, | 659 GENERIC_WRITE, |
664 0, | 660 0, |
665 NULL, | 661 NULL, |
666 CREATE_ALWAYS, | 662 CREATE_ALWAYS, |
667 0, | 663 0, |
668 NULL)); | 664 NULL)); |
669 if (file == INVALID_HANDLE_VALUE) { | 665 if (file == INVALID_HANDLE_VALUE) { |
670 LOG(WARNING) << "CreateFile failed for path " << filename.value() << | 666 LOG(WARNING) << "CreateFile failed for path " << filename.value() << |
671 " error code=" << GetLastError() << | 667 " error code=" << GetLastError() << |
672 " error text=" << win_util::FormatLastWin32Error(); | 668 " error text=" << win_util::FormatLastWin32Error(); |
673 return -1; | 669 return -1; |
674 } | 670 } |
675 | 671 |
676 DWORD written; | 672 DWORD written; |
677 BOOL result = ::WriteFile(file, data, size, &written, NULL); | 673 BOOL result = ::WriteFile(file, data, size, &written, NULL); |
678 if (result && written == size) | 674 if (result && static_cast<int>(written) == size) |
679 return static_cast<int>(written); | 675 return written; |
680 | 676 |
681 if (!result) { | 677 if (!result) { |
682 // WriteFile failed. | 678 // WriteFile failed. |
683 LOG(WARNING) << "writing file " << filename.value() << | 679 LOG(WARNING) << "writing file " << filename.value() << |
684 " failed, error code=" << GetLastError() << | 680 " failed, error code=" << GetLastError() << |
685 " description=" << win_util::FormatLastWin32Error(); | 681 " description=" << win_util::FormatLastWin32Error(); |
686 } else { | 682 } else { |
687 // Didn't write all the bytes. | 683 // Didn't write all the bytes. |
688 LOG(WARNING) << "wrote" << written << " bytes to " << | 684 LOG(WARNING) << "wrote" << written << " bytes to " << |
689 filename.value() << " expected " << size; | 685 filename.value() << " expected " << size; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 } | 886 } |
891 | 887 |
892 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, | 888 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, |
893 const base::Time& cutoff_time) { | 889 const base::Time& cutoff_time) { |
894 long result = CompareFileTime(&find_info.ftLastWriteTime, | 890 long result = CompareFileTime(&find_info.ftLastWriteTime, |
895 &cutoff_time.ToFileTime()); | 891 &cutoff_time.ToFileTime()); |
896 return result == 1 || result == 0; | 892 return result == 1 || result == 0; |
897 } | 893 } |
898 | 894 |
899 } // namespace file_util | 895 } // namespace file_util |
OLD | NEW |