| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <stdint.h> |
| 6 | 7 |
| 7 #include "chrome/installer/util/logging_installer.h" | 8 #include "chrome/installer/util/logging_installer.h" |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/logging_win.h" | 15 #include "base/logging_win.h" |
| 15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 26 | 27 |
| 27 namespace installer { | 28 namespace installer { |
| 28 | 29 |
| 29 // This should be true for the period between the end of | 30 // This should be true for the period between the end of |
| 30 // InitInstallerLogging() and the beginning of EndInstallerLogging(). | 31 // InitInstallerLogging() and the beginning of EndInstallerLogging(). |
| 31 bool installer_logging_ = false; | 32 bool installer_logging_ = false; |
| 32 | 33 |
| 33 TruncateResult TruncateLogFileIfNeeded(const base::FilePath& log_file) { | 34 TruncateResult TruncateLogFileIfNeeded(const base::FilePath& log_file) { |
| 34 TruncateResult result = LOGFILE_UNTOUCHED; | 35 TruncateResult result = LOGFILE_UNTOUCHED; |
| 35 | 36 |
| 36 int64 log_size = 0; | 37 int64_t log_size = 0; |
| 37 if (base::GetFileSize(log_file, &log_size) && | 38 if (base::GetFileSize(log_file, &log_size) && |
| 38 log_size > kMaxInstallerLogFileSize) { | 39 log_size > kMaxInstallerLogFileSize) { |
| 39 // Cause the old log file to be deleted when we are done with it. | 40 // Cause the old log file to be deleted when we are done with it. |
| 40 uint32 file_flags = base::File::FLAG_OPEN | | 41 uint32_t file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 41 base::File::FLAG_READ | | 42 base::File::FLAG_SHARE_DELETE | |
| 42 base::File::FLAG_SHARE_DELETE | | 43 base::File::FLAG_DELETE_ON_CLOSE; |
| 43 base::File::FLAG_DELETE_ON_CLOSE; | |
| 44 base::File old_log_file(log_file, file_flags); | 44 base::File old_log_file(log_file, file_flags); |
| 45 | 45 |
| 46 if (old_log_file.IsValid()) { | 46 if (old_log_file.IsValid()) { |
| 47 result = LOGFILE_DELETED; | 47 result = LOGFILE_DELETED; |
| 48 base::FilePath tmp_log(log_file.value() + FILE_PATH_LITERAL(".tmp")); | 48 base::FilePath tmp_log(log_file.value() + FILE_PATH_LITERAL(".tmp")); |
| 49 // Note that base::Move will attempt to replace existing files. | 49 // Note that base::Move will attempt to replace existing files. |
| 50 if (base::Move(log_file, tmp_log)) { | 50 if (base::Move(log_file, tmp_log)) { |
| 51 int64 offset = log_size - kTruncatedInstallerLogFileSize; | 51 int64_t offset = log_size - kTruncatedInstallerLogFileSize; |
| 52 std::string old_log_data(kTruncatedInstallerLogFileSize, 0); | 52 std::string old_log_data(kTruncatedInstallerLogFileSize, 0); |
| 53 int bytes_read = old_log_file.Read(offset, | 53 int bytes_read = old_log_file.Read(offset, |
| 54 &old_log_data[0], | 54 &old_log_data[0], |
| 55 kTruncatedInstallerLogFileSize); | 55 kTruncatedInstallerLogFileSize); |
| 56 if (bytes_read > 0 && | 56 if (bytes_read > 0 && |
| 57 (bytes_read == base::WriteFile(log_file, &old_log_data[0], | 57 (bytes_read == base::WriteFile(log_file, &old_log_data[0], |
| 58 bytes_read) || | 58 bytes_read) || |
| 59 base::PathExists(log_file))) { | 59 base::PathExists(log_file))) { |
| 60 result = LOGFILE_TRUNCATED; | 60 result = LOGFILE_TRUNCATED; |
| 61 } | 61 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 static const base::FilePath::CharType kLogFilename[] = | 117 static const base::FilePath::CharType kLogFilename[] = |
| 118 FILE_PATH_LITERAL("chrome_installer.log"); | 118 FILE_PATH_LITERAL("chrome_installer.log"); |
| 119 | 119 |
| 120 // Fallback to current directory if getting the temp directory fails. | 120 // Fallback to current directory if getting the temp directory fails. |
| 121 base::FilePath tmp_path; | 121 base::FilePath tmp_path; |
| 122 ignore_result(PathService::Get(base::DIR_TEMP, &tmp_path)); | 122 ignore_result(PathService::Get(base::DIR_TEMP, &tmp_path)); |
| 123 return tmp_path.Append(kLogFilename); | 123 return tmp_path.Append(kLogFilename); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace installer | 126 } // namespace installer |
| OLD | NEW |