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

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

Issue 13654002: Change how File/Directory/Link .delete works. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <fcntl.h> // NOLINT 10 #include <fcntl.h> // NOLINT
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 NULL); 252 NULL);
253 if (CloseHandle(dir_handle) == 0) return false; 253 if (CloseHandle(dir_handle) == 0) return false;
254 free(const_cast<wchar_t*>(target)); 254 free(const_cast<wchar_t*>(target));
255 free(reparse_data_buffer); 255 free(reparse_data_buffer);
256 return (result != 0); 256 return (result != 0);
257 } 257 }
258 258
259 259
260 bool File::Delete(const char* name) { 260 bool File::Delete(const char* name) {
261 const wchar_t* system_name = StringUtils::Utf8ToWide(name); 261 const wchar_t* system_name = StringUtils::Utf8ToWide(name);
262 int status = _wremove(system_name);
263 free(const_cast<wchar_t*>(system_name));
264 return status != -1;
265 }
266
267
268 bool File::DeleteLink(const char* name) {
269 const wchar_t* system_name = StringUtils::Utf8ToWide(name);
270 bool result = false;
262 DWORD attributes = GetFileAttributesW(system_name); 271 DWORD attributes = GetFileAttributesW(system_name);
263 if ((attributes != INVALID_FILE_ATTRIBUTES) && 272 if ((attributes != INVALID_FILE_ATTRIBUTES) &&
264 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { 273 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
265 // It's a junction(link), delete it. 274 // It's a junction(link), delete it.
266 return RemoveDirectoryW(system_name) != 0; 275 result = (RemoveDirectoryW(system_name) != 0);
267 } else {
268 int status = _wremove(system_name);
269 free(const_cast<wchar_t*>(system_name));
270 if (status == -1) {
271 return false;
272 }
273 return true;
274 } 276 }
277 free(const_cast<wchar_t*>(system_name));
278 return result;
275 } 279 }
276 280
277 281
278 off_t File::LengthFromPath(const char* name) { 282 off_t File::LengthFromPath(const char* name) {
279 struct _stat st; 283 struct _stat st;
280 const wchar_t* system_name = StringUtils::Utf8ToWide(name); 284 const wchar_t* system_name = StringUtils::Utf8ToWide(name);
281 int stat_status = _wstat(system_name, &st); 285 int stat_status = _wstat(system_name, &st);
282 free(const_cast<wchar_t*>(system_name)); 286 free(const_cast<wchar_t*>(system_name));
283 if (stat_status == 0) { 287 if (stat_status == 0) {
284 return st.st_size; 288 return st.st_size;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 477
474 File::StdioHandleType File::GetStdioHandleType(int fd) { 478 File::StdioHandleType File::GetStdioHandleType(int fd) {
475 // Treat all stdio handles as pipes. The Windows event handler and 479 // Treat all stdio handles as pipes. The Windows event handler and
476 // socket code will handle the different handle types. 480 // socket code will handle the different handle types.
477 return kPipe; 481 return kPipe;
478 } 482 }
479 483
480 484
481 File::Type File::GetType(const char* pathname, bool follow_links) { 485 File::Type File::GetType(const char* pathname, bool follow_links) {
482 const wchar_t* name = StringUtils::Utf8ToWide(pathname); 486 const wchar_t* name = StringUtils::Utf8ToWide(pathname);
483 WIN32_FIND_DATAW file_data; 487 DWORD attributes = GetFileAttributesW(name);
484 HANDLE find_handle = FindFirstFileW(name, &file_data); 488 File::Type result = kIsFile;
485 if (find_handle == INVALID_HANDLE_VALUE) { 489 if (attributes == INVALID_FILE_ATTRIBUTES) {
486 // TODO(whesse): Distinguish other errors from does not exist. 490 result = kDoesNotExist;
487 return File::kDoesNotExist; 491 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
488 }
489 FindClose(find_handle);
490 DWORD attributes = file_data.dwFileAttributes;
491 if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
492 if (follow_links) { 492 if (follow_links) {
493 HANDLE dir_handle = CreateFileW( 493 HANDLE dir_handle = CreateFileW(
494 name, 494 name,
495 0, 495 0,
496 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 496 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
497 NULL, 497 NULL,
498 OPEN_EXISTING, 498 OPEN_EXISTING,
499 FILE_FLAG_BACKUP_SEMANTICS, 499 FILE_FLAG_BACKUP_SEMANTICS,
500 NULL); 500 NULL);
501 if (dir_handle == INVALID_HANDLE_VALUE) { 501 if (dir_handle == INVALID_HANDLE_VALUE) {
502 // TODO(whesse): Distinguish other errors from does not exist. 502 result = File::kIsLink;
503 return File::kDoesNotExist;
504 } else { 503 } else {
505 CloseHandle(dir_handle); 504 CloseHandle(dir_handle);
506 return File::kIsDirectory; 505 result = File::kIsDirectory;
507 } 506 }
508 } else { 507 } else {
509 DWORD reparse_tag = file_data.dwReserved0; 508 result = kIsLink;
510 if (reparse_tag == IO_REPARSE_TAG_SYMLINK ||
511 reparse_tag == IO_REPARSE_TAG_MOUNT_POINT) {
512 return File::kIsLink;
513 } else {
514 return File::kDoesNotExist;
515 }
516 } 509 }
517 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { 510 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
518 return File::kIsDirectory; 511 result = kIsDirectory;
519 } else {
520 return File::kIsFile;
521 } 512 }
513 free(const_cast<wchar_t*>(name));
514 return result;
522 } 515 }
523 516
524 517
525 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { 518 File::Identical File::AreIdentical(const char* file_1, const char* file_2) {
526 BY_HANDLE_FILE_INFORMATION file_info[2]; 519 BY_HANDLE_FILE_INFORMATION file_info[2];
527 const char* file_names[2] = { file_1, file_2 }; 520 const char* file_names[2] = { file_1, file_2 };
528 for (int i = 0; i < 2; ++i) { 521 for (int i = 0; i < 2; ++i) {
529 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]); 522 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]);
530 HANDLE file_handle = CreateFileW( 523 HANDLE file_handle = CreateFileW(
531 wide_name, 524 wide_name,
(...skipping 24 matching lines...) Expand all
556 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber && 549 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber &&
557 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh && 550 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh &&
558 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) { 551 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) {
559 return kIdentical; 552 return kIdentical;
560 } else { 553 } else {
561 return kDifferent; 554 return kDifferent;
562 } 555 }
563 } 556 }
564 557
565 #endif // defined(TARGET_OS_WINDOWS) 558 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698