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

Side by Side Diff: base/mac/mac_util.mm

Issue 6990066: Mac TimeMachine File Exclusions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months 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 | « no previous file | base/mac/mac_util_unittest.mm » ('j') | base/mac/mac_util_unittest.mm » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/mac/mac_util.h" 5 #include "base/mac/mac_util.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 void ActivateProcess(pid_t pid) { 231 void ActivateProcess(pid_t pid) {
232 ProcessSerialNumber process; 232 ProcessSerialNumber process;
233 OSStatus status = GetProcessForPID(pid, &process); 233 OSStatus status = GetProcessForPID(pid, &process);
234 if (status == noErr) { 234 if (status == noErr) {
235 SetFrontProcess(&process); 235 SetFrontProcess(&process);
236 } else { 236 } else {
237 LOG(WARNING) << "Unable to get process for pid " << pid; 237 LOG(WARNING) << "Unable to get process for pid " << pid;
238 } 238 }
239 } 239 }
240 240
241 bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) { 241 bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) {
Mark Mentovai 2011/05/25 01:14:35 This entire function should be cleaned up substant
mrossetti 2011/05/26 21:02:40 Done.
242 NSString* filePath = 242 NSString* filePath =
243 [NSString stringWithUTF8String:file_path.value().c_str()]; 243 [NSString stringWithUTF8String:file_path.value().c_str()];
244 244
245 // If being asked to exclude something in a tmp directory, just lie and say it 245 // If being asked to exclude something in a tmp directory, just lie and say it
246 // was done. TimeMachine will already ignore tmp directories. This keeps the 246 // was done. TimeMachine will already ignore tmp directories. This keeps the
247 // temporary profiles used by unittests from being added to the exclude list. 247 // temporary profiles used by unittests from being added to the exclude list.
248 // Otherwise, as /Library/Preferences/com.apple.TimeMachine.plist grows the 248 // Otherwise, as /Library/Preferences/com.apple.TimeMachine.plist grows the
249 // bots slow down due to reading/writing all the temporary profiles used over 249 // bots slow down due to reading/writing all the temporary profiles used over
250 // time. 250 // time.
251 251
252 NSString* tmpDir = NSTemporaryDirectory(); 252 NSString* tmpDir = NSTemporaryDirectory();
253 // Make sure the temp dir is terminated with a slash 253 // Make sure the temp dir is terminated with a slash
254 if (tmpDir && ![tmpDir hasSuffix:@"/"]) 254 if (tmpDir && ![tmpDir hasSuffix:@"/"])
255 tmpDir = [tmpDir stringByAppendingString:@"/"]; 255 tmpDir = [tmpDir stringByAppendingString:@"/"];
256 // '/var' is a link to '/private/var', make sure to check both forms. 256 // '/var' is a link to '/private/var', make sure to check both forms.
257 NSString* privateTmpDir = nil; 257 NSString* privateTmpDir = nil;
258 if ([tmpDir hasPrefix:@"/var/"]) 258 if ([tmpDir hasPrefix:@"/var/"])
259 privateTmpDir = [@"/private" stringByAppendingString:tmpDir]; 259 privateTmpDir = [@"/private" stringByAppendingString:tmpDir];
260 260
261 if ((tmpDir && [filePath hasPrefix:tmpDir]) || 261 if ((tmpDir && [filePath hasPrefix:tmpDir]) ||
262 (privateTmpDir && [filePath hasPrefix:privateTmpDir]) || 262 (privateTmpDir && [filePath hasPrefix:privateTmpDir]) ||
263 [filePath hasPrefix:@"/tmp/"] || 263 [filePath hasPrefix:@"/tmp/"] ||
264 [filePath hasPrefix:@"/var/tmp/"] || 264 [filePath hasPrefix:@"/var/tmp/"] ||
265 [filePath hasPrefix:@"/private/tmp/"] || 265 [filePath hasPrefix:@"/private/tmp/"] ||
266 [filePath hasPrefix:@"/private/var/tmp/"]) { 266 [filePath hasPrefix:@"/private/var/tmp/"]) {
267 return true; 267 return true;
268 } 268 }
269 269
270 NSURL* url = [NSURL fileURLWithPath:filePath]; 270 NSURL* url = [NSURL fileURLWithPath:filePath];
271 // Note that we always set CSBackupSetItemExcluded's excludeByPath param 271 // When excludeByPath is true the application must be running with root
272 // to true. This prevents a problem with toggling the setting: if the file 272 // privileges (admin for 10.6 and earlier) but the URL does not have to
273 // is excluded with excludeByPath set to true then excludeByPath must 273 // already exist. When excludeByPath is false the URL must already exist but
274 // also be true when un-excluding the file, otherwise the un-excluding 274 // can be used in non-root (or admin as above) mode. We use false so that
275 // will be ignored. 275 // non-root (or admin) users don't get their TimeMachine drive filled up with
276 // unnecessary backups.
276 bool success = 277 bool success =
277 CSBackupSetItemExcluded((CFURLRef)url, exclude, true) == noErr; 278 CSBackupSetItemExcluded((CFURLRef)url, exclude, false) == noErr;
278 if (!success) 279 if (!success)
Mark Mentovai 2011/05/25 01:14:35 Style nit (present in the existing code): this nee
mrossetti 2011/05/26 21:02:40 Done.
279 LOG(WARNING) << "Failed to set backup exclusion for file '" 280 LOG(WARNING) << "Failed to set backup exclusion for file '"
280 << file_path.value().c_str() << "'. Continuing."; 281 << file_path.value().c_str() << "'. Continuing.";
281 return success; 282 return success;
282 } 283 }
283 284
284 void SetProcessName(CFStringRef process_name) { 285 void SetProcessName(CFStringRef process_name) {
285 if (!process_name || CFStringGetLength(process_name) == 0) { 286 if (!process_name || CFStringGetLength(process_name) == 0) {
286 NOTREACHED() << "SetProcessName given bad name."; 287 NOTREACHED() << "SetProcessName given bad name.";
287 return; 288 return;
288 } 289 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); 476 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
476 if (!item.get()) { 477 if (!item.get()) {
477 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; 478 LOG(ERROR) << "Process launched at Login but can't access Login Item List.";
478 return false; 479 return false;
479 } 480 }
480 return IsHiddenLoginItem(item); 481 return IsHiddenLoginItem(item);
481 } 482 }
482 483
483 } // namespace mac 484 } // namespace mac
484 } // namespace base 485 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/mac/mac_util_unittest.mm » ('j') | base/mac/mac_util_unittest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698