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 <errno.h> // NOLINT | |
Søren Gjesse
2013/04/08 07:21:18
No need for this
Anders Johnsen
2013/04/08 07:44:04
Done.
| |
10 #include <fcntl.h> // NOLINT | 11 #include <fcntl.h> // NOLINT |
11 #include <io.h> // NOLINT | 12 #include <io.h> // NOLINT |
12 #include <stdio.h> // NOLINT | 13 #include <stdio.h> // NOLINT |
13 #include <string.h> // NOLINT | 14 #include <string.h> // NOLINT |
14 #include <sys/stat.h> // NOLINT | 15 #include <sys/stat.h> // NOLINT |
15 #include <WinIoCtl.h> // NOLINT | 16 #include <WinIoCtl.h> // NOLINT |
16 | 17 |
17 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
18 #include "bin/log.h" | 19 #include "bin/log.h" |
19 | 20 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 NULL); | 253 NULL); |
253 if (CloseHandle(dir_handle) == 0) return false; | 254 if (CloseHandle(dir_handle) == 0) return false; |
254 free(const_cast<wchar_t*>(target)); | 255 free(const_cast<wchar_t*>(target)); |
255 free(reparse_data_buffer); | 256 free(reparse_data_buffer); |
256 return (result != 0); | 257 return (result != 0); |
257 } | 258 } |
258 | 259 |
259 | 260 |
260 bool File::Delete(const char* name) { | 261 bool File::Delete(const char* name) { |
261 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 262 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
263 int status = _wremove(system_name); | |
264 free(const_cast<wchar_t*>(system_name)); | |
265 return status != -1; | |
266 } | |
267 | |
268 | |
269 bool File::DeleteLink(const char* name) { | |
270 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | |
271 bool result = false; | |
262 DWORD attributes = GetFileAttributesW(system_name); | 272 DWORD attributes = GetFileAttributesW(system_name); |
263 if ((attributes != INVALID_FILE_ATTRIBUTES) && | 273 if ((attributes != INVALID_FILE_ATTRIBUTES) && |
264 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 274 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
265 // It's a junction(link), delete it. | 275 // It's a junction(link), delete it. |
266 return RemoveDirectoryW(system_name) != 0; | 276 result = (RemoveDirectoryW(system_name) != 0); |
267 } else { | 277 } else { |
268 int status = _wremove(system_name); | 278 errno = EINVAL; |
Søren Gjesse
2013/04/08 07:21:18
SetLastError
Anders Johnsen
2013/04/08 07:44:04
Done.
| |
269 free(const_cast<wchar_t*>(system_name)); | |
270 if (status == -1) { | |
271 return false; | |
272 } | |
273 return true; | |
274 } | 279 } |
280 free(const_cast<wchar_t*>(system_name)); | |
281 return result; | |
275 } | 282 } |
276 | 283 |
277 | 284 |
278 off_t File::LengthFromPath(const char* name) { | 285 off_t File::LengthFromPath(const char* name) { |
279 struct _stat st; | 286 struct _stat st; |
280 const wchar_t* system_name = StringUtils::Utf8ToWide(name); | 287 const wchar_t* system_name = StringUtils::Utf8ToWide(name); |
281 int stat_status = _wstat(system_name, &st); | 288 int stat_status = _wstat(system_name, &st); |
282 free(const_cast<wchar_t*>(system_name)); | 289 free(const_cast<wchar_t*>(system_name)); |
283 if (stat_status == 0) { | 290 if (stat_status == 0) { |
284 return st.st_size; | 291 return st.st_size; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 | 480 |
474 File::StdioHandleType File::GetStdioHandleType(int fd) { | 481 File::StdioHandleType File::GetStdioHandleType(int fd) { |
475 // Treat all stdio handles as pipes. The Windows event handler and | 482 // Treat all stdio handles as pipes. The Windows event handler and |
476 // socket code will handle the different handle types. | 483 // socket code will handle the different handle types. |
477 return kPipe; | 484 return kPipe; |
478 } | 485 } |
479 | 486 |
480 | 487 |
481 File::Type File::GetType(const char* pathname, bool follow_links) { | 488 File::Type File::GetType(const char* pathname, bool follow_links) { |
482 const wchar_t* name = StringUtils::Utf8ToWide(pathname); | 489 const wchar_t* name = StringUtils::Utf8ToWide(pathname); |
483 WIN32_FIND_DATAW file_data; | 490 DWORD attributes = GetFileAttributesW(name); |
484 HANDLE find_handle = FindFirstFileW(name, &file_data); | 491 File::Type result = kIsFile; |
485 if (find_handle == INVALID_HANDLE_VALUE) { | 492 if (attributes == INVALID_FILE_ATTRIBUTES) { |
486 // TODO(whesse): Distinguish other errors from does not exist. | 493 result = kDoesNotExist; |
487 return File::kDoesNotExist; | 494 } 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) { | 495 if (follow_links) { |
493 HANDLE dir_handle = CreateFileW( | 496 HANDLE dir_handle = CreateFileW( |
494 name, | 497 name, |
495 0, | 498 0, |
496 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 499 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
497 NULL, | 500 NULL, |
498 OPEN_EXISTING, | 501 OPEN_EXISTING, |
499 FILE_FLAG_BACKUP_SEMANTICS, | 502 FILE_FLAG_BACKUP_SEMANTICS, |
500 NULL); | 503 NULL); |
501 if (dir_handle == INVALID_HANDLE_VALUE) { | 504 if (dir_handle == INVALID_HANDLE_VALUE) { |
502 // TODO(whesse): Distinguish other errors from does not exist. | 505 result = File::kIsLink; |
503 return File::kDoesNotExist; | |
504 } else { | 506 } else { |
505 CloseHandle(dir_handle); | 507 CloseHandle(dir_handle); |
506 return File::kIsDirectory; | 508 result = File::kIsDirectory; |
507 } | 509 } |
508 } else { | 510 } else { |
509 DWORD reparse_tag = file_data.dwReserved0; | 511 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 } | 512 } |
517 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 513 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
518 return File::kIsDirectory; | 514 result = kIsDirectory; |
519 } else { | |
520 return File::kIsFile; | |
521 } | 515 } |
516 free(const_cast<wchar_t*>(name)); | |
517 return result; | |
522 } | 518 } |
523 | 519 |
524 | 520 |
525 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { | 521 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { |
526 BY_HANDLE_FILE_INFORMATION file_info[2]; | 522 BY_HANDLE_FILE_INFORMATION file_info[2]; |
527 const char* file_names[2] = { file_1, file_2 }; | 523 const char* file_names[2] = { file_1, file_2 }; |
528 for (int i = 0; i < 2; ++i) { | 524 for (int i = 0; i < 2; ++i) { |
529 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]); | 525 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]); |
530 HANDLE file_handle = CreateFileW( | 526 HANDLE file_handle = CreateFileW( |
531 wide_name, | 527 wide_name, |
(...skipping 24 matching lines...) Expand all Loading... | |
556 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber && | 552 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber && |
557 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh && | 553 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh && |
558 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) { | 554 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) { |
559 return kIdentical; | 555 return kIdentical; |
560 } else { | 556 } else { |
561 return kDifferent; | 557 return kDifferent; |
562 } | 558 } |
563 } | 559 } |
564 | 560 |
565 #endif // defined(TARGET_OS_WINDOWS) | 561 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |