OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This file defines helper methods used to schedule files for deletion | 5 // This file defines helper methods used to schedule files for deletion |
6 // on next reboot. The code here is heavily borrowed and simplified from | 6 // on next reboot. The code here is heavily borrowed and simplified from |
7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and | 7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and |
8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc | 8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc |
9 // | 9 // |
10 // This implementation really is not fast, so do not use it where that will | 10 // This implementation really is not fast, so do not use it where that will |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (*s == L'.' && s > dir_name && *(s - 1) == L'.') { | 47 if (*s == L'.' && s > dir_name && *(s - 1) == L'.') { |
48 return false; | 48 return false; |
49 } | 49 } |
50 if (*s == L':') { | 50 if (*s == L':') { |
51 ok = false; | 51 ok = false; |
52 } | 52 } |
53 } | 53 } |
54 return ok; | 54 return ok; |
55 } | 55 } |
56 | 56 |
| 57 } // end namespace |
| 58 |
57 // Must only be called for regular files or directories that will be empty. | 59 // Must only be called for regular files or directories that will be empty. |
58 bool ScheduleFileSystemEntityForDeletion(const wchar_t* path) { | 60 bool ScheduleFileSystemEntityForDeletion(const wchar_t* path) { |
59 // Check if the file exists, return false if not. | 61 // Check if the file exists, return false if not. |
60 WIN32_FILE_ATTRIBUTE_DATA attrs = {0}; | 62 WIN32_FILE_ATTRIBUTE_DATA attrs = {0}; |
61 if (!::GetFileAttributesEx(path, ::GetFileExInfoStandard, &attrs)) { | 63 if (!::GetFileAttributesEx(path, ::GetFileExInfoStandard, &attrs)) { |
62 LOG(ERROR) << path << " for deletion does not exist." << GetLastError(); | 64 LOG(ERROR) << path << " for deletion does not exist." << GetLastError(); |
63 return false; | 65 return false; |
64 } | 66 } |
65 | 67 |
66 DWORD flags = MOVEFILE_DELAY_UNTIL_REBOOT; | 68 DWORD flags = MOVEFILE_DELAY_UNTIL_REBOOT; |
67 if (!file_util::DirectoryExists(FilePath::FromWStringHack(path))) { | 69 if (!file_util::DirectoryExists(FilePath::FromWStringHack(path))) { |
68 // This flag valid only for files | 70 // This flag valid only for files |
69 flags |= MOVEFILE_REPLACE_EXISTING; | 71 flags |= MOVEFILE_REPLACE_EXISTING; |
70 } | 72 } |
71 | 73 |
72 if (!::MoveFileEx(path, NULL, flags)) { | 74 if (!::MoveFileEx(path, NULL, flags)) { |
73 LOG(ERROR) << "Could not schedule " << path << " for deletion."; | 75 LOG(ERROR) << "Could not schedule " << path << " for deletion."; |
74 return false; | 76 return false; |
75 } | 77 } |
76 | 78 |
77 LOG(INFO) << "Scheduled for deletion: " << path; | 79 LOG(INFO) << "Scheduled for deletion: " << path; |
78 return true; | 80 return true; |
79 } | 81 } |
80 } // end namespace | |
81 | 82 |
82 bool ScheduleDirectoryForDeletion(const wchar_t* dir_name) { | 83 bool ScheduleDirectoryForDeletion(const wchar_t* dir_name) { |
83 if (!IsSafeDirectoryNameForDeletion(dir_name)) { | 84 if (!IsSafeDirectoryNameForDeletion(dir_name)) { |
84 LOG(ERROR) << "Unsafe directory name for deletion: " << dir_name; | 85 LOG(ERROR) << "Unsafe directory name for deletion: " << dir_name; |
85 return false; | 86 return false; |
86 } | 87 } |
87 | 88 |
88 // Make sure the directory exists (it is ok if it doesn't) | 89 // Make sure the directory exists (it is ok if it doesn't) |
89 DWORD dir_attributes = ::GetFileAttributes(dir_name); | 90 DWORD dir_attributes = ::GetFileAttributes(dir_name); |
90 if (dir_attributes == INVALID_FILE_ATTRIBUTES) { | 91 if (dir_attributes == INVALID_FILE_ATTRIBUTES) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 return session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], | 367 return session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], |
367 buffer.size(), REG_MULTI_SZ); | 368 buffer.size(), REG_MULTI_SZ); |
368 } else { | 369 } else { |
369 return false; | 370 return false; |
370 } | 371 } |
371 } else { | 372 } else { |
372 // We have only the trailing NULL string. Don't bother writing that. | 373 // We have only the trailing NULL string. Don't bother writing that. |
373 return session_manager_key.DeleteValue(kPendingFileRenameOps); | 374 return session_manager_key.DeleteValue(kPendingFileRenameOps); |
374 } | 375 } |
375 } | 376 } |
OLD | NEW |