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

Side by Side Diff: runtime/bin/directory_android.cc

Issue 13578003: Fix directory-listing, directory-deletion and file deletion, when links are involved. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use Link for Link removal. Created 7 years, 8 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 | runtime/bin/directory_linux.cc » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 9
10 #include <dirent.h> // NOLINT 10 #include <dirent.h> // NOLINT
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // the actual entry type. Notice that stat returns the type of 162 // the actual entry type. Notice that stat returns the type of
163 // the file pointed to. 163 // the file pointed to.
164 struct stat entry_info; 164 struct stat entry_info;
165 if (!path->Add(entry.d_name)) { 165 if (!path->Add(entry.d_name)) {
166 success = false; 166 success = false;
167 break; 167 break;
168 } 168 }
169 int stat_success; 169 int stat_success;
170 if (follow_links) { 170 if (follow_links) {
171 stat_success = TEMP_FAILURE_RETRY(stat(path->data, &entry_info)); 171 stat_success = TEMP_FAILURE_RETRY(stat(path->data, &entry_info));
172 if (stat_success == -1) {
173 stat_success = TEMP_FAILURE_RETRY(lstat(path->data, &entry_info));
174 }
172 } else { 175 } else {
173 stat_success = TEMP_FAILURE_RETRY(lstat(path->data, &entry_info)); 176 stat_success = TEMP_FAILURE_RETRY(lstat(path->data, &entry_info));
174 } 177 }
175 if (stat_success == -1) { 178 if (stat_success == -1) {
176 success = false; 179 success = false;
177 PostError(listing, path->data); 180 PostError(listing, path->data);
178 break; 181 break;
179 } 182 }
180 path->Reset(path_length); 183 path->Reset(path_length);
181 if (S_ISDIR(entry_info.st_mode)) { 184 if (S_ISDIR(entry_info.st_mode)) {
182 success = HandleDir(entry.d_name, 185 success = HandleDir(entry.d_name,
183 path, 186 path,
184 recursive, 187 recursive,
185 follow_links, 188 follow_links,
186 listing) && success; 189 listing) && success;
187 } else if (S_ISREG(entry_info.st_mode)) { 190 } else if (S_ISREG(entry_info.st_mode)) {
188 success = HandleFile(entry.d_name, 191 success = HandleFile(entry.d_name,
189 path, 192 path,
190 listing) && success; 193 listing) && success;
191 } else if (S_ISLNK(entry_info.st_mode)) { 194 } else if (S_ISLNK(entry_info.st_mode)) {
192 ASSERT(!follow_links);
193 success = HandleLink(entry.d_name, 195 success = HandleLink(entry.d_name,
194 path, 196 path,
195 listing) && success; 197 listing) && success;
196 } 198 }
197 break; 199 break;
198 } 200 }
199 default: 201 default:
200 break; 202 break;
201 } 203 }
202 path->Reset(path_length); 204 path->Reset(path_length);
(...skipping 22 matching lines...) Expand all
225 227
226 static bool DeleteDir(char* dir_name, 228 static bool DeleteDir(char* dir_name,
227 PathBuffer* path) { 229 PathBuffer* path) {
228 if (strcmp(dir_name, ".") == 0) return true; 230 if (strcmp(dir_name, ".") == 0) return true;
229 if (strcmp(dir_name, "..") == 0) return true; 231 if (strcmp(dir_name, "..") == 0) return true;
230 return path->Add(dir_name) && DeleteRecursively(path); 232 return path->Add(dir_name) && DeleteRecursively(path);
231 } 233 }
232 234
233 235
234 static bool DeleteRecursively(PathBuffer* path) { 236 static bool DeleteRecursively(PathBuffer* path) {
235 if (!path->Add(File::PathSeparator())) return false;
236 // Do not recurse into links for deletion. Instead delete the link. 237 // Do not recurse into links for deletion. Instead delete the link.
237 struct stat st; 238 struct stat st;
238 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) { 239 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) {
239 return false; 240 return false;
240 } else if (S_ISLNK(st.st_mode)) { 241 } else if (S_ISLNK(st.st_mode)) {
241 return (remove(path->data) == 0); 242 return (remove(path->data) == 0);
242 } 243 }
243 244
245 if (!path->Add(File::PathSeparator())) return false;
246
244 // Not a link. Attempt to open as a directory and recurse into the 247 // Not a link. Attempt to open as a directory and recurse into the
245 // directory. 248 // directory.
246 DIR* dir_pointer; 249 DIR* dir_pointer;
247 do { 250 do {
248 dir_pointer = opendir(path->data); 251 dir_pointer = opendir(path->data);
249 } while (dir_pointer == NULL && errno == EINTR); 252 } while (dir_pointer == NULL && errno == EINTR);
250 253
251 if (dir_pointer == NULL) { 254 if (dir_pointer == NULL) {
252 return false; 255 return false;
253 } 256 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 452 }
450 453
451 454
452 bool Directory::Rename(const char* path, const char* new_path) { 455 bool Directory::Rename(const char* path, const char* new_path) {
453 ExistsResult exists = Exists(path); 456 ExistsResult exists = Exists(path);
454 if (exists != EXISTS) return false; 457 if (exists != EXISTS) return false;
455 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 458 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
456 } 459 }
457 460
458 #endif // defined(TARGET_OS_ANDROID) 461 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/directory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698