Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: chrome/common/logging_chrome.cc

Issue 5286010: Start using file_util symlink code, now that it's available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review change Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/process_singleton_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 // Need to include this before most other files because it defines 7 // Need to include this before most other files because it defines
8 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define 8 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
9 // IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the 9 // IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the
10 // ViewMsgLog et al. functions. 10 // ViewMsgLog et al. functions.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // If not starting a new log, then just log through the existing 157 // If not starting a new log, then just log through the existing
158 // symlink, but if the symlink doesn't exist, create it. If 158 // symlink, but if the symlink doesn't exist, create it. If
159 // starting a new log, then delete the old symlink and make a new 159 // starting a new log, then delete the old symlink and make a new
160 // one to a fresh log file. 160 // one to a fresh log file.
161 FilePath target_path; 161 FilePath target_path;
162 bool symlink_exists = file_util::PathExists(symlink_path); 162 bool symlink_exists = file_util::PathExists(symlink_path);
163 if (new_log || !symlink_exists) { 163 if (new_log || !symlink_exists) {
164 target_path = GenerateTimestampedName(symlink_path, base::Time::Now()); 164 target_path = GenerateTimestampedName(symlink_path, base::Time::Now());
165 165
166 // We don't care if the unlink fails; we're going to continue anyway. 166 // We don't care if the unlink fails; we're going to continue anyway.
167 if (unlink(symlink_path.value().c_str()) == -1) { 167 if (::unlink(symlink_path.value().c_str()) == -1) {
168 if (symlink_exists) // only warn if we might expect it to succeed. 168 if (symlink_exists) // only warn if we might expect it to succeed.
169 PLOG(WARNING) << "Unable to unlink " << symlink_path.value(); 169 PLOG(WARNING) << "Unable to unlink " << symlink_path.value();
170 } 170 }
171 if (symlink(target_path.value().c_str(), 171 if (!file_util::CreateSymbolicLink(target_path, symlink_path)) {
172 symlink_path.value().c_str()) == -1) {
173 PLOG(ERROR) << "Unable to create symlink " << symlink_path.value() 172 PLOG(ERROR) << "Unable to create symlink " << symlink_path.value()
174 << " pointing at " << target_path.value(); 173 << " pointing at " << target_path.value();
175 } 174 }
176 } else { 175 } else {
177 char buf[PATH_MAX]; 176 if (!file_util::ReadSymbolicLink(symlink_path, &target_path))
178 ssize_t count = readlink(symlink_path.value().c_str(), buf, arraysize(buf));
179 if (count > 0) {
180 target_path = FilePath(FilePath::StringType(buf, count));
181 } else {
182 PLOG(ERROR) << "Unable to read symlink " << symlink_path.value(); 177 PLOG(ERROR) << "Unable to read symlink " << symlink_path.value();
183 }
184 } 178 }
185 return target_path; 179 return target_path;
186 } 180 }
187 181
188 void RemoveSymlinkAndLog(const FilePath& link_path, 182 void RemoveSymlinkAndLog(const FilePath& link_path,
189 const FilePath& target_path) { 183 const FilePath& target_path) {
190 if (::unlink(link_path.value().c_str()) == -1) 184 if (::unlink(link_path.value().c_str()) == -1)
191 PLOG(WARNING) << "Unable to unlink symlink " << link_path.value(); 185 PLOG(WARNING) << "Unable to unlink symlink " << link_path.value();
192 if (::unlink(target_path.value().c_str()) == -1) 186 if (::unlink(target_path.value().c_str()) == -1)
193 PLOG(WARNING) << "Unable to unlink log file " << target_path.value(); 187 PLOG(WARNING) << "Unable to unlink log file " << target_path.value();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 assertions->push_back(wide_line); 384 assertions->push_back(wide_line);
391 ++assertion_count; 385 ++assertion_count;
392 } 386 }
393 } 387 }
394 log_file.close(); 388 log_file.close();
395 389
396 return assertion_count; 390 return assertion_count;
397 } 391 }
398 392
399 } // namespace logging 393 } // namespace logging
OLDNEW
« no previous file with comments | « chrome/browser/process_singleton_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698