| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <psapi.h> | 8 #include <psapi.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 int WriteFile(const FilePath& filename, const char* data, int size) { | 593 int WriteFile(const FilePath& filename, const char* data, int size) { |
| 594 ThreadRestrictions::AssertIOAllowed(); | 594 ThreadRestrictions::AssertIOAllowed(); |
| 595 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), | 595 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 596 GENERIC_WRITE, | 596 GENERIC_WRITE, |
| 597 0, | 597 0, |
| 598 NULL, | 598 NULL, |
| 599 CREATE_ALWAYS, | 599 CREATE_ALWAYS, |
| 600 0, | 600 0, |
| 601 NULL)); | 601 NULL)); |
| 602 if (!file) { | 602 if (!file) { |
| 603 DLOG_GETLASTERROR(WARNING) << "CreateFile failed for path " | 603 DPLOG(WARNING) << "CreateFile failed for path " |
| 604 << UTF16ToUTF8(filename.value()); | 604 << UTF16ToUTF8(filename.value()); |
| 605 return -1; | 605 return -1; |
| 606 } | 606 } |
| 607 | 607 |
| 608 DWORD written; | 608 DWORD written; |
| 609 BOOL result = ::WriteFile(file, data, size, &written, NULL); | 609 BOOL result = ::WriteFile(file, data, size, &written, NULL); |
| 610 if (result && static_cast<int>(written) == size) | 610 if (result && static_cast<int>(written) == size) |
| 611 return written; | 611 return written; |
| 612 | 612 |
| 613 if (!result) { | 613 if (!result) { |
| 614 // WriteFile failed. | 614 // WriteFile failed. |
| 615 DLOG_GETLASTERROR(WARNING) << "writing file " | 615 DPLOG(WARNING) << "writing file " << UTF16ToUTF8(filename.value()) |
| 616 << UTF16ToUTF8(filename.value()) << " failed"; | 616 << " failed"; |
| 617 } else { | 617 } else { |
| 618 // Didn't write all the bytes. | 618 // Didn't write all the bytes. |
| 619 DLOG(WARNING) << "wrote" << written << " bytes to " | 619 DLOG(WARNING) << "wrote" << written << " bytes to " |
| 620 << UTF16ToUTF8(filename.value()) << " expected " << size; | 620 << UTF16ToUTF8(filename.value()) << " expected " << size; |
| 621 } | 621 } |
| 622 return -1; | 622 return -1; |
| 623 } | 623 } |
| 624 | 624 |
| 625 int AppendToFile(const FilePath& filename, const char* data, int size) { | 625 int AppendToFile(const FilePath& filename, const char* data, int size) { |
| 626 ThreadRestrictions::AssertIOAllowed(); | 626 ThreadRestrictions::AssertIOAllowed(); |
| 627 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), | 627 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 628 FILE_APPEND_DATA, | 628 FILE_APPEND_DATA, |
| 629 0, | 629 0, |
| 630 NULL, | 630 NULL, |
| 631 OPEN_EXISTING, | 631 OPEN_EXISTING, |
| 632 0, | 632 0, |
| 633 NULL)); | 633 NULL)); |
| 634 if (!file) { | 634 if (!file) { |
| 635 DLOG_GETLASTERROR(WARNING) << "CreateFile failed for path " | 635 DPLOG(WARNING) << "CreateFile failed for path " |
| 636 << UTF16ToUTF8(filename.value()); | 636 << UTF16ToUTF8(filename.value()); |
| 637 return -1; | 637 return -1; |
| 638 } | 638 } |
| 639 | 639 |
| 640 DWORD written; | 640 DWORD written; |
| 641 BOOL result = ::WriteFile(file, data, size, &written, NULL); | 641 BOOL result = ::WriteFile(file, data, size, &written, NULL); |
| 642 if (result && static_cast<int>(written) == size) | 642 if (result && static_cast<int>(written) == size) |
| 643 return written; | 643 return written; |
| 644 | 644 |
| 645 if (!result) { | 645 if (!result) { |
| 646 // WriteFile failed. | 646 // WriteFile failed. |
| 647 DLOG_GETLASTERROR(WARNING) << "writing file " | 647 DPLOG(WARNING) << "writing file " << UTF16ToUTF8(filename.value()) |
| 648 << UTF16ToUTF8(filename.value()) | 648 << " failed"; |
| 649 << " failed"; | |
| 650 } else { | 649 } else { |
| 651 // Didn't write all the bytes. | 650 // Didn't write all the bytes. |
| 652 DLOG(WARNING) << "wrote" << written << " bytes to " | 651 DLOG(WARNING) << "wrote" << written << " bytes to " |
| 653 << UTF16ToUTF8(filename.value()) << " expected " << size; | 652 << UTF16ToUTF8(filename.value()) << " expected " << size; |
| 654 } | 653 } |
| 655 return -1; | 654 return -1; |
| 656 } | 655 } |
| 657 | 656 |
| 658 // Gets the current working directory for the process. | 657 // Gets the current working directory for the process. |
| 659 bool GetCurrentDirectory(FilePath* dir) { | 658 bool GetCurrentDirectory(FilePath* dir) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 // Like Move, this function is not transactional, so we just | 779 // Like Move, this function is not transactional, so we just |
| 781 // leave the copied bits behind if deleting from_path fails. | 780 // leave the copied bits behind if deleting from_path fails. |
| 782 // If to_path exists previously then we have already overwritten | 781 // If to_path exists previously then we have already overwritten |
| 783 // it by now, we don't get better off by deleting the new bits. | 782 // it by now, we don't get better off by deleting the new bits. |
| 784 } | 783 } |
| 785 return false; | 784 return false; |
| 786 } | 785 } |
| 787 | 786 |
| 788 } // namespace internal | 787 } // namespace internal |
| 789 } // namespace base | 788 } // namespace base |
| OLD | NEW |