| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <psapi.h> | 9 #include <psapi.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 DPLOG(WARNING) << "writing file " << UTF16ToUTF8(filename.value()) | 637 DPLOG(WARNING) << "writing file " << UTF16ToUTF8(filename.value()) |
| 638 << " failed"; | 638 << " failed"; |
| 639 } else { | 639 } else { |
| 640 // Didn't write all the bytes. | 640 // Didn't write all the bytes. |
| 641 DLOG(WARNING) << "wrote" << written << " bytes to " | 641 DLOG(WARNING) << "wrote" << written << " bytes to " |
| 642 << UTF16ToUTF8(filename.value()) << " expected " << size; | 642 << UTF16ToUTF8(filename.value()) << " expected " << size; |
| 643 } | 643 } |
| 644 return -1; | 644 return -1; |
| 645 } | 645 } |
| 646 | 646 |
| 647 int AppendToFile(const FilePath& filename, const char* data, int size) { | 647 bool AppendToFile(const FilePath& filename, const char* data, int size) { |
| 648 ThreadRestrictions::AssertIOAllowed(); | 648 ThreadRestrictions::AssertIOAllowed(); |
| 649 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), | 649 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 650 FILE_APPEND_DATA, | 650 FILE_APPEND_DATA, |
| 651 0, | 651 0, |
| 652 NULL, | 652 NULL, |
| 653 OPEN_EXISTING, | 653 OPEN_EXISTING, |
| 654 0, | 654 0, |
| 655 NULL)); | 655 NULL)); |
| 656 if (!file.IsValid()) { | 656 if (!file.IsValid()) { |
| 657 DPLOG(WARNING) << "CreateFile failed for path " | 657 VPLOG(1) << "CreateFile failed for path " << UTF16ToUTF8(filename.value()); |
| 658 << UTF16ToUTF8(filename.value()); | 658 return false; |
| 659 return -1; | |
| 660 } | 659 } |
| 661 | 660 |
| 662 DWORD written; | 661 DWORD written; |
| 663 BOOL result = ::WriteFile(file.Get(), data, size, &written, NULL); | 662 BOOL result = ::WriteFile(file.Get(), data, size, &written, NULL); |
| 664 if (result && static_cast<int>(written) == size) | 663 if (result && static_cast<int>(written) == size) |
| 665 return written; | 664 return true; |
| 666 | 665 |
| 667 if (!result) { | 666 if (!result) { |
| 668 // WriteFile failed. | 667 // WriteFile failed. |
| 669 DPLOG(WARNING) << "writing file " << UTF16ToUTF8(filename.value()) | 668 VPLOG(1) << "Writing file " << UTF16ToUTF8(filename.value()) << " failed"; |
| 670 << " failed"; | |
| 671 } else { | 669 } else { |
| 672 // Didn't write all the bytes. | 670 // Didn't write all the bytes. |
| 673 DLOG(WARNING) << "wrote" << written << " bytes to " | 671 VPLOG(1) << "Only wrote " << written << " out of " << size << " byte(s) to " |
| 674 << UTF16ToUTF8(filename.value()) << " expected " << size; | 672 << UTF16ToUTF8(filename.value()); |
| 675 } | 673 } |
| 676 return -1; | 674 return false; |
| 677 } | 675 } |
| 678 | 676 |
| 679 // Gets the current working directory for the process. | 677 // Gets the current working directory for the process. |
| 680 bool GetCurrentDirectory(FilePath* dir) { | 678 bool GetCurrentDirectory(FilePath* dir) { |
| 681 ThreadRestrictions::AssertIOAllowed(); | 679 ThreadRestrictions::AssertIOAllowed(); |
| 682 | 680 |
| 683 wchar_t system_buffer[MAX_PATH]; | 681 wchar_t system_buffer[MAX_PATH]; |
| 684 system_buffer[0] = 0; | 682 system_buffer[0] = 0; |
| 685 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); | 683 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); |
| 686 if (len == 0 || len > MAX_PATH) | 684 if (len == 0 || len > MAX_PATH) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // Like Move, this function is not transactional, so we just | 799 // Like Move, this function is not transactional, so we just |
| 802 // leave the copied bits behind if deleting from_path fails. | 800 // leave the copied bits behind if deleting from_path fails. |
| 803 // If to_path exists previously then we have already overwritten | 801 // If to_path exists previously then we have already overwritten |
| 804 // it by now, we don't get better off by deleting the new bits. | 802 // it by now, we don't get better off by deleting the new bits. |
| 805 } | 803 } |
| 806 return false; | 804 return false; |
| 807 } | 805 } |
| 808 | 806 |
| 809 } // namespace internal | 807 } // namespace internal |
| 810 } // namespace base | 808 } // namespace base |
| OLD | NEW |