Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { | 276 } else { |
| 268 int status = _wremove(system_name); | 277 SetLastError(ERROR_NOT_A_REPARSE_POINT); |
| 269 free(const_cast<wchar_t*>(system_name)); | |
| 270 if (status == -1) { | |
| 271 return false; | |
| 272 } | |
| 273 return true; | |
| 274 } | 278 } |
| 279 free(const_cast<wchar_t*>(system_name)); | |
|
Bill Hesse
2013/04/08 12:16:33
I think there is a problem calling "free" between
Anders Johnsen
2013/04/08 12:22:34
Can you link me some info on the problem? I'm not
| |
| 280 return result; | |
| 275 } | 281 } |
| 276 | 282 |
| 277 | 283 |
| 278 off_t File::LengthFromPath(const char* name) { | 284 off_t File::LengthFromPath(const char* name) { |
| 279 struct _stat st; | 285 struct _stat st; |
| 280 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 286 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
| 281 int stat_status = _wstat(system_name, &st); | 287 int stat_status = _wstat(system_name, &st); |
| 282 free(const_cast<wchar_t*>(system_name)); | 288 free(const_cast<wchar_t*>(system_name)); |
| 283 if (stat_status == 0) { | 289 if (stat_status == 0) { |
| 284 return st.st_size; | 290 return st.st_size; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 | 479 |
| 474 File::StdioHandleType File::GetStdioHandleType(int fd) { | 480 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 475 // Treat all stdio handles as pipes. The Windows event handler and | 481 // Treat all stdio handles as pipes. The Windows event handler and |
| 476 // socket code will handle the different handle types. | 482 // socket code will handle the different handle types. |
| 477 return kPipe; | 483 return kPipe; |
| 478 } | 484 } |
| 479 | 485 |
| 480 | 486 |
| 481 File::Type File::GetType(const char* pathname, bool follow_links) { | 487 File::Type File::GetType(const char* pathname, bool follow_links) { |
| 482 const wchar_t* name = StringUtils::Utf8ToWide(pathname); | 488 const wchar_t* name = StringUtils::Utf8ToWide(pathname); |
| 483 WIN32_FIND_DATAW file_data; | 489 DWORD attributes = GetFileAttributesW(name); |
| 484 HANDLE find_handle = FindFirstFileW(name, &file_data); | 490 File::Type result = kIsFile; |
| 485 if (find_handle == INVALID_HANDLE_VALUE) { | 491 if (attributes == INVALID_FILE_ATTRIBUTES) { |
| 486 // TODO(whesse): Distinguish other errors from does not exist. | 492 result = kDoesNotExist; |
| 487 return File::kDoesNotExist; | 493 } 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) { | 494 if (follow_links) { |
| 493 HANDLE dir_handle = CreateFileW( | 495 HANDLE dir_handle = CreateFileW( |
| 494 name, | 496 name, |
| 495 0, | 497 0, |
| 496 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 498 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 497 NULL, | 499 NULL, |
| 498 OPEN_EXISTING, | 500 OPEN_EXISTING, |
| 499 FILE_FLAG_BACKUP_SEMANTICS, | 501 FILE_FLAG_BACKUP_SEMANTICS, |
| 500 NULL); | 502 NULL); |
| 501 if (dir_handle == INVALID_HANDLE_VALUE) { | 503 if (dir_handle == INVALID_HANDLE_VALUE) { |
| 502 // TODO(whesse): Distinguish other errors from does not exist. | 504 result = File::kIsLink; |
| 503 return File::kDoesNotExist; | |
| 504 } else { | 505 } else { |
| 505 CloseHandle(dir_handle); | 506 CloseHandle(dir_handle); |
|
Bill Hesse
2013/04/08 12:16:33
Since we have the handle to the file, and this mig
Anders Johnsen
2013/04/08 12:22:34
I understand now. Yes, we should probably add that
| |
| 506 return File::kIsDirectory; | 507 result = File::kIsDirectory; |
| 507 } | 508 } |
| 508 } else { | 509 } else { |
| 509 DWORD reparse_tag = file_data.dwReserved0; | 510 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 } | 511 } |
| 517 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 512 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
| 518 return File::kIsDirectory; | 513 result = kIsDirectory; |
| 519 } else { | |
| 520 return File::kIsFile; | |
| 521 } | 514 } |
| 515 free(const_cast<wchar_t*>(name)); | |
| 516 return result; | |
| 522 } | 517 } |
| 523 | 518 |
| 524 | 519 |
| 525 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { | 520 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
| 526 BY_HANDLE_FILE_INFORMATION file_info[2]; | 521 BY_HANDLE_FILE_INFORMATION file_info[2]; |
| 527 const char* file_names[2] = { file_1, file_2 }; | 522 const char* file_names[2] = { file_1, file_2 }; |
| 528 for (int i = 0; i < 2; ++i) { | 523 for (int i = 0; i < 2; ++i) { |
| 529 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]); | 524 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]); |
| 530 HANDLE file_handle = CreateFileW( | 525 HANDLE file_handle = CreateFileW( |
| 531 wide_name, | 526 wide_name, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 556 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber && | 551 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber && |
| 557 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh && | 552 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh && |
| 558 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) { | 553 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) { |
| 559 return kIdentical; | 554 return kIdentical; |
| 560 } else { | 555 } else { |
| 561 return kDifferent; | 556 return kDifferent; |
| 562 } | 557 } |
| 563 } | 558 } |
| 564 | 559 |
| 565 #endif // defined(TARGET_OS_WINDOWS) | 560 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |