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(HOST_OS_WINDOWS) | 6 #if defined(HOST_OS_WINDOWS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <WinIoCtl.h> // NOLINT | 10 #include <WinIoCtl.h> // NOLINT |
11 #include <fcntl.h> // NOLINT | 11 #include <fcntl.h> // NOLINT |
12 #include <io.h> // NOLINT | 12 #include <io.h> // NOLINT |
13 #include <stdio.h> // NOLINT | 13 #include <stdio.h> // NOLINT |
14 #include <string.h> // NOLINT | 14 #include <string.h> // NOLINT |
15 #include <sys/stat.h> // NOLINT | 15 #include <sys/stat.h> // NOLINT |
16 #include <sys/utime.h> // NOLINT | 16 #include <sys/utime.h> // NOLINT |
17 | 17 |
18 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
19 #include "bin/log.h" | 19 #include "bin/log.h" |
| 20 #include "bin/namespace.h" |
20 #include "bin/utils.h" | 21 #include "bin/utils.h" |
21 #include "bin/utils_win.h" | 22 #include "bin/utils_win.h" |
22 #include "platform/utils.h" | 23 #include "platform/utils.h" |
23 | 24 |
24 namespace dart { | 25 namespace dart { |
25 namespace bin { | 26 namespace bin { |
26 | 27 |
27 class FileHandle { | 28 class FileHandle { |
28 public: | 29 public: |
29 explicit FileHandle(int fd) : fd_(fd) {} | 30 explicit FileHandle(int fd) : fd_(fd) {} |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || | 266 if ((((mode & kWrite) != 0) && ((mode & kTruncate) == 0)) || |
266 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { | 267 (((mode & kWriteOnly) != 0) && ((mode & kTruncate) == 0))) { |
267 int64_t position = _lseeki64(fd, 0, SEEK_END); | 268 int64_t position = _lseeki64(fd, 0, SEEK_END); |
268 if (position < 0) { | 269 if (position < 0) { |
269 return NULL; | 270 return NULL; |
270 } | 271 } |
271 } | 272 } |
272 return new File(new FileHandle(fd)); | 273 return new File(new FileHandle(fd)); |
273 } | 274 } |
274 | 275 |
275 File* File::Open(const char* path, FileOpenMode mode) { | 276 File* File::Open(Namespace* namespc, const char* path, FileOpenMode mode) { |
276 Utf8ToWideScope system_name(path); | 277 Utf8ToWideScope system_name(path); |
277 File* file = FileOpenW(system_name.wide(), mode); | 278 File* file = FileOpenW(system_name.wide(), mode); |
278 return file; | 279 return file; |
279 } | 280 } |
280 | 281 |
281 File* File::OpenStdio(int fd) { | 282 File* File::OpenStdio(int fd) { |
282 int stdio_fd = -1; | 283 int stdio_fd = -1; |
283 switch (fd) { | 284 switch (fd) { |
284 case 1: | 285 case 1: |
285 stdio_fd = _fileno(stdout); | 286 stdio_fd = _fileno(stdout); |
(...skipping 13 matching lines...) Expand all Loading... |
299 if (stat_status != 0) { | 300 if (stat_status != 0) { |
300 return false; | 301 return false; |
301 } | 302 } |
302 if ((st->st_mode & S_IFMT) != S_IFREG) { | 303 if ((st->st_mode & S_IFMT) != S_IFREG) { |
303 SetLastError(ERROR_NOT_SUPPORTED); | 304 SetLastError(ERROR_NOT_SUPPORTED); |
304 return false; | 305 return false; |
305 } | 306 } |
306 return true; | 307 return true; |
307 } | 308 } |
308 | 309 |
309 bool File::Exists(const char* name) { | 310 bool File::Exists(Namespace* namespc, const char* name) { |
310 struct __stat64 st; | 311 struct __stat64 st; |
311 Utf8ToWideScope system_name(name); | 312 Utf8ToWideScope system_name(name); |
312 return StatHelper(system_name.wide(), &st); | 313 return StatHelper(system_name.wide(), &st); |
313 } | 314 } |
314 | 315 |
315 bool File::Create(const char* name) { | 316 bool File::Create(Namespace* namespc, const char* name) { |
316 Utf8ToWideScope system_name(name); | 317 Utf8ToWideScope system_name(name); |
317 int fd = _wopen(system_name.wide(), O_RDONLY | O_CREAT, 0666); | 318 int fd = _wopen(system_name.wide(), O_RDONLY | O_CREAT, 0666); |
318 if (fd < 0) { | 319 if (fd < 0) { |
319 return false; | 320 return false; |
320 } | 321 } |
321 return (close(fd) == 0); | 322 return (close(fd) == 0); |
322 } | 323 } |
323 | 324 |
324 // This structure is needed for creating and reading Junctions. | 325 // This structure is needed for creating and reading Junctions. |
325 typedef struct _REPARSE_DATA_BUFFER { | 326 typedef struct _REPARSE_DATA_BUFFER { |
(...skipping 21 matching lines...) Expand all Loading... |
347 | 348 |
348 struct { | 349 struct { |
349 UCHAR DataBuffer[1]; | 350 UCHAR DataBuffer[1]; |
350 } GenericReparseBuffer; | 351 } GenericReparseBuffer; |
351 }; | 352 }; |
352 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; | 353 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; |
353 | 354 |
354 static const int kReparseDataHeaderSize = sizeof ULONG + 2 * sizeof USHORT; | 355 static const int kReparseDataHeaderSize = sizeof ULONG + 2 * sizeof USHORT; |
355 static const int kMountPointHeaderSize = 4 * sizeof USHORT; | 356 static const int kMountPointHeaderSize = 4 * sizeof USHORT; |
356 | 357 |
357 bool File::CreateLink(const char* utf8_name, const char* utf8_target) { | 358 bool File::CreateLink(Namespace* namespc, const char* utf8_name, const char* utf
8_target) { |
358 Utf8ToWideScope name(utf8_name); | 359 Utf8ToWideScope name(utf8_name); |
359 int create_status = CreateDirectoryW(name.wide(), NULL); | 360 int create_status = CreateDirectoryW(name.wide(), NULL); |
360 // If the directory already existed, treat it as a success. | 361 // If the directory already existed, treat it as a success. |
361 if ((create_status == 0) && | 362 if ((create_status == 0) && |
362 ((GetLastError() != ERROR_ALREADY_EXISTS) || | 363 ((GetLastError() != ERROR_ALREADY_EXISTS) || |
363 ((GetFileAttributesW(name.wide()) & FILE_ATTRIBUTE_DIRECTORY) != 0))) { | 364 ((GetFileAttributesW(name.wide()) & FILE_ATTRIBUTE_DIRECTORY) != 0))) { |
364 return false; | 365 return false; |
365 } | 366 } |
366 | 367 |
367 HANDLE dir_handle = CreateFileW( | 368 HANDLE dir_handle = CreateFileW( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 dir_handle, FSCTL_SET_REPARSE_POINT, reparse_data_buffer, | 405 dir_handle, FSCTL_SET_REPARSE_POINT, reparse_data_buffer, |
405 reparse_data_buffer->ReparseDataLength + kReparseDataHeaderSize, NULL, 0, | 406 reparse_data_buffer->ReparseDataLength + kReparseDataHeaderSize, NULL, 0, |
406 &dummy_received_bytes, NULL); | 407 &dummy_received_bytes, NULL); |
407 free(reparse_data_buffer); | 408 free(reparse_data_buffer); |
408 if (CloseHandle(dir_handle) == 0) { | 409 if (CloseHandle(dir_handle) == 0) { |
409 return false; | 410 return false; |
410 } | 411 } |
411 return (result != 0); | 412 return (result != 0); |
412 } | 413 } |
413 | 414 |
414 bool File::Delete(const char* name) { | 415 bool File::Delete(Namespace* namespc, const char* name) { |
415 Utf8ToWideScope system_name(name); | 416 Utf8ToWideScope system_name(name); |
416 int status = _wremove(system_name.wide()); | 417 int status = _wremove(system_name.wide()); |
417 return status != -1; | 418 return status != -1; |
418 } | 419 } |
419 | 420 |
420 bool File::DeleteLink(const char* name) { | 421 bool File::DeleteLink(Namespace* namespc, const char* name) { |
421 Utf8ToWideScope system_name(name); | 422 Utf8ToWideScope system_name(name); |
422 bool result = false; | 423 bool result = false; |
423 DWORD attributes = GetFileAttributesW(system_name.wide()); | 424 DWORD attributes = GetFileAttributesW(system_name.wide()); |
424 if ((attributes != INVALID_FILE_ATTRIBUTES) && | 425 if ((attributes != INVALID_FILE_ATTRIBUTES) && |
425 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 426 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
426 // It's a junction(link), delete it. | 427 // It's a junction(link), delete it. |
427 result = (RemoveDirectoryW(system_name.wide()) != 0); | 428 result = (RemoveDirectoryW(system_name.wide()) != 0); |
428 } else { | 429 } else { |
429 SetLastError(ERROR_NOT_A_REPARSE_POINT); | 430 SetLastError(ERROR_NOT_A_REPARSE_POINT); |
430 } | 431 } |
431 return result; | 432 return result; |
432 } | 433 } |
433 | 434 |
434 bool File::Rename(const char* old_path, const char* new_path) { | 435 bool File::Rename(Namespace* namespc, const char* old_path, const char* new_path
) { |
435 File::Type type = GetType(old_path, false); | 436 File::Type type = GetType(namespc, old_path, false); |
436 if (type == kIsFile) { | 437 if (type == kIsFile) { |
437 Utf8ToWideScope system_old_path(old_path); | 438 Utf8ToWideScope system_old_path(old_path); |
438 Utf8ToWideScope system_new_path(new_path); | 439 Utf8ToWideScope system_new_path(new_path); |
439 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; | 440 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; |
440 int move_status = | 441 int move_status = |
441 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); | 442 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); |
442 return (move_status != 0); | 443 return (move_status != 0); |
443 } else { | 444 } else { |
444 SetLastError(ERROR_FILE_NOT_FOUND); | 445 SetLastError(ERROR_FILE_NOT_FOUND); |
445 } | 446 } |
446 return false; | 447 return false; |
447 } | 448 } |
448 | 449 |
449 bool File::RenameLink(const char* old_path, const char* new_path) { | 450 bool File::RenameLink(Namespace* namespc, const char* old_path, const char* new_
path) { |
450 File::Type type = GetType(old_path, false); | 451 File::Type type = GetType(namespc, old_path, false); |
451 if (type == kIsLink) { | 452 if (type == kIsLink) { |
452 Utf8ToWideScope system_old_path(old_path); | 453 Utf8ToWideScope system_old_path(old_path); |
453 Utf8ToWideScope system_new_path(new_path); | 454 Utf8ToWideScope system_new_path(new_path); |
454 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; | 455 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; |
455 int move_status = | 456 int move_status = |
456 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); | 457 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); |
457 return (move_status != 0); | 458 return (move_status != 0); |
458 } else { | 459 } else { |
459 SetLastError(ERROR_FILE_NOT_FOUND); | 460 SetLastError(ERROR_FILE_NOT_FOUND); |
460 } | 461 } |
461 return false; | 462 return false; |
462 } | 463 } |
463 | 464 |
464 bool File::Copy(const char* old_path, const char* new_path) { | 465 bool File::Copy(Namespace* namespc, const char* old_path, const char* new_path)
{ |
465 File::Type type = GetType(old_path, false); | 466 File::Type type = GetType(namespc, old_path, false); |
466 if (type == kIsFile) { | 467 if (type == kIsFile) { |
467 Utf8ToWideScope system_old_path(old_path); | 468 Utf8ToWideScope system_old_path(old_path); |
468 Utf8ToWideScope system_new_path(new_path); | 469 Utf8ToWideScope system_new_path(new_path); |
469 bool success = CopyFileExW(system_old_path.wide(), system_new_path.wide(), | 470 bool success = CopyFileExW(system_old_path.wide(), system_new_path.wide(), |
470 NULL, NULL, NULL, 0) != 0; | 471 NULL, NULL, NULL, 0) != 0; |
471 return success; | 472 return success; |
472 } else { | 473 } else { |
473 SetLastError(ERROR_FILE_NOT_FOUND); | 474 SetLastError(ERROR_FILE_NOT_FOUND); |
474 } | 475 } |
475 return false; | 476 return false; |
476 } | 477 } |
477 | 478 |
478 int64_t File::LengthFromPath(const char* name) { | 479 int64_t File::LengthFromPath(Namespace* namespc, const char* name) { |
479 struct __stat64 st; | 480 struct __stat64 st; |
480 Utf8ToWideScope system_name(name); | 481 Utf8ToWideScope system_name(name); |
481 if (!StatHelper(system_name.wide(), &st)) { | 482 if (!StatHelper(system_name.wide(), &st)) { |
482 return -1; | 483 return -1; |
483 } | 484 } |
484 return st.st_size; | 485 return st.st_size; |
485 } | 486 } |
486 | 487 |
487 const char* File::LinkTarget(const char* pathname) { | 488 const char* File::LinkTarget(Namespace* namespc, const char* pathname) { |
488 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); | 489 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); |
489 HANDLE dir_handle = CreateFileW( | 490 HANDLE dir_handle = CreateFileW( |
490 name, GENERIC_READ, | 491 name, GENERIC_READ, |
491 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 492 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
492 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, | 493 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, |
493 NULL); | 494 NULL); |
494 if (dir_handle == INVALID_HANDLE_VALUE) { | 495 if (dir_handle == INVALID_HANDLE_VALUE) { |
495 return NULL; | 496 return NULL; |
496 } | 497 } |
497 | 498 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 0, NULL, NULL); | 541 0, NULL, NULL); |
541 char* utf8_target = DartUtils::ScopedCString(utf8_length + 1); | 542 char* utf8_target = DartUtils::ScopedCString(utf8_length + 1); |
542 if (0 == WideCharToMultiByte(CP_UTF8, 0, target, target_length, utf8_target, | 543 if (0 == WideCharToMultiByte(CP_UTF8, 0, target, target_length, utf8_target, |
543 utf8_length, NULL, NULL)) { | 544 utf8_length, NULL, NULL)) { |
544 return NULL; | 545 return NULL; |
545 } | 546 } |
546 utf8_target[utf8_length] = '\0'; | 547 utf8_target[utf8_length] = '\0'; |
547 return utf8_target; | 548 return utf8_target; |
548 } | 549 } |
549 | 550 |
550 void File::Stat(const char* name, int64_t* data) { | 551 void File::Stat(Namespace* namespc, const char* name, int64_t* data) { |
551 File::Type type = GetType(name, false); | 552 File::Type type = GetType(namespc, name, false); |
552 data[kType] = type; | 553 data[kType] = type; |
553 if (type != kDoesNotExist) { | 554 if (type != kDoesNotExist) { |
554 struct _stat64 st; | 555 struct _stat64 st; |
555 Utf8ToWideScope system_name(name); | 556 Utf8ToWideScope system_name(name); |
556 int stat_status = _wstat64(system_name.wide(), &st); | 557 int stat_status = _wstat64(system_name.wide(), &st); |
557 if (stat_status == 0) { | 558 if (stat_status == 0) { |
558 data[kCreatedTime] = st.st_ctime * 1000; | 559 data[kCreatedTime] = st.st_ctime * 1000; |
559 data[kModifiedTime] = st.st_mtime * 1000; | 560 data[kModifiedTime] = st.st_mtime * 1000; |
560 data[kAccessedTime] = st.st_atime * 1000; | 561 data[kAccessedTime] = st.st_atime * 1000; |
561 data[kMode] = st.st_mode; | 562 data[kMode] = st.st_mode; |
562 data[kSize] = st.st_size; | 563 data[kSize] = st.st_size; |
563 } else { | 564 } else { |
564 data[kType] = File::kDoesNotExist; | 565 data[kType] = File::kDoesNotExist; |
565 } | 566 } |
566 } | 567 } |
567 } | 568 } |
568 | 569 |
569 time_t File::LastAccessed(const char* name) { | 570 time_t File::LastAccessed(Namespace* namespc, const char* name) { |
570 struct __stat64 st; | 571 struct __stat64 st; |
571 Utf8ToWideScope system_name(name); | 572 Utf8ToWideScope system_name(name); |
572 if (!StatHelper(system_name.wide(), &st)) { | 573 if (!StatHelper(system_name.wide(), &st)) { |
573 return -1; | 574 return -1; |
574 } | 575 } |
575 return st.st_atime; | 576 return st.st_atime; |
576 } | 577 } |
577 | 578 |
578 time_t File::LastModified(const char* name) { | 579 time_t File::LastModified(Namespace* namespc, const char* name) { |
579 struct __stat64 st; | 580 struct __stat64 st; |
580 Utf8ToWideScope system_name(name); | 581 Utf8ToWideScope system_name(name); |
581 if (!StatHelper(system_name.wide(), &st)) { | 582 if (!StatHelper(system_name.wide(), &st)) { |
582 return -1; | 583 return -1; |
583 } | 584 } |
584 return st.st_mtime; | 585 return st.st_mtime; |
585 } | 586 } |
586 | 587 |
587 bool File::SetLastAccessed(const char* name, int64_t millis) { | 588 bool File::SetLastAccessed(Namespace* namespc, const char* name, int64_t millis)
{ |
588 // First get the current times. | 589 // First get the current times. |
589 struct __stat64 st; | 590 struct __stat64 st; |
590 Utf8ToWideScope system_name(name); | 591 Utf8ToWideScope system_name(name); |
591 if (!StatHelper(system_name.wide(), &st)) { | 592 if (!StatHelper(system_name.wide(), &st)) { |
592 return false; | 593 return false; |
593 } | 594 } |
594 | 595 |
595 // Set the new time: | 596 // Set the new time: |
596 struct __utimbuf64 times; | 597 struct __utimbuf64 times; |
597 times.actime = millis / kMillisecondsPerSecond; | 598 times.actime = millis / kMillisecondsPerSecond; |
598 times.modtime = st.st_mtime; | 599 times.modtime = st.st_mtime; |
599 return _wutime64(system_name.wide(), ×) == 0; | 600 return _wutime64(system_name.wide(), ×) == 0; |
600 } | 601 } |
601 | 602 |
602 bool File::SetLastModified(const char* name, int64_t millis) { | 603 bool File::SetLastModified(Namespace* namespc, const char* name, int64_t millis)
{ |
603 // First get the current times. | 604 // First get the current times. |
604 struct __stat64 st; | 605 struct __stat64 st; |
605 Utf8ToWideScope system_name(name); | 606 Utf8ToWideScope system_name(name); |
606 if (!StatHelper(system_name.wide(), &st)) { | 607 if (!StatHelper(system_name.wide(), &st)) { |
607 return false; | 608 return false; |
608 } | 609 } |
609 | 610 |
610 // Set the new time: | 611 // Set the new time: |
611 struct __utimbuf64 times; | 612 struct __utimbuf64 times; |
612 times.actime = st.st_atime; | 613 times.actime = st.st_atime; |
613 times.modtime = millis / kMillisecondsPerSecond; | 614 times.modtime = millis / kMillisecondsPerSecond; |
614 return _wutime64(system_name.wide(), ×) == 0; | 615 return _wutime64(system_name.wide(), ×) == 0; |
615 } | 616 } |
616 | 617 |
617 bool File::IsAbsolutePath(const char* pathname) { | 618 bool File::IsAbsolutePath(const char* pathname) { |
618 // Should we consider network paths? | 619 // Should we consider network paths? |
619 if (pathname == NULL) { | 620 if (pathname == NULL) { |
620 return false; | 621 return false; |
621 } | 622 } |
622 return ((strlen(pathname) > 2) && (pathname[1] == ':') && | 623 return ((strlen(pathname) > 2) && (pathname[1] == ':') && |
623 ((pathname[2] == '\\') || (pathname[2] == '/'))); | 624 ((pathname[2] == '\\') || (pathname[2] == '/'))); |
624 } | 625 } |
625 | 626 |
626 const char* File::GetCanonicalPath(const char* pathname) { | 627 const char* File::GetCanonicalPath(Namespace* namespc, const char* pathname) { |
627 Utf8ToWideScope system_name(pathname); | 628 Utf8ToWideScope system_name(pathname); |
628 HANDLE file_handle = | 629 HANDLE file_handle = |
629 CreateFileW(system_name.wide(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, | 630 CreateFileW(system_name.wide(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
630 FILE_FLAG_BACKUP_SEMANTICS, NULL); | 631 FILE_FLAG_BACKUP_SEMANTICS, NULL); |
631 if (file_handle == INVALID_HANDLE_VALUE) { | 632 if (file_handle == INVALID_HANDLE_VALUE) { |
632 return NULL; | 633 return NULL; |
633 } | 634 } |
634 wchar_t dummy_buffer[1]; | 635 wchar_t dummy_buffer[1]; |
635 int required_size = | 636 int required_size = |
636 GetFinalPathNameByHandle(file_handle, dummy_buffer, 0, VOLUME_NAME_DOS); | 637 GetFinalPathNameByHandle(file_handle, dummy_buffer, 0, VOLUME_NAME_DOS); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 // This is already UTF-8 encoded. | 669 // This is already UTF-8 encoded. |
669 return "\\\\"; | 670 return "\\\\"; |
670 } | 671 } |
671 | 672 |
672 File::StdioHandleType File::GetStdioHandleType(int fd) { | 673 File::StdioHandleType File::GetStdioHandleType(int fd) { |
673 // Treat all stdio handles as pipes. The Windows event handler and | 674 // Treat all stdio handles as pipes. The Windows event handler and |
674 // socket code will handle the different handle types. | 675 // socket code will handle the different handle types. |
675 return kPipe; | 676 return kPipe; |
676 } | 677 } |
677 | 678 |
678 File::Type File::GetType(const char* pathname, bool follow_links) { | 679 File::Type File::GetType(Namespace* namespc, const char* pathname, bool follow_l
inks) { |
679 // Convert to wchar_t string. | 680 // Convert to wchar_t string. |
680 Utf8ToWideScope name(pathname); | 681 Utf8ToWideScope name(pathname); |
681 DWORD attributes = GetFileAttributesW(name.wide()); | 682 DWORD attributes = GetFileAttributesW(name.wide()); |
682 File::Type result = kIsFile; | 683 File::Type result = kIsFile; |
683 if (attributes == INVALID_FILE_ATTRIBUTES) { | 684 if (attributes == INVALID_FILE_ATTRIBUTES) { |
684 result = kDoesNotExist; | 685 result = kDoesNotExist; |
685 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 686 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
686 if (follow_links) { | 687 if (follow_links) { |
687 HANDLE dir_handle = | 688 HANDLE dir_handle = |
688 CreateFileW(name.wide(), 0, | 689 CreateFileW(name.wide(), 0, |
689 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 690 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
690 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 691 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
691 if (dir_handle == INVALID_HANDLE_VALUE) { | 692 if (dir_handle == INVALID_HANDLE_VALUE) { |
692 result = File::kIsLink; | 693 result = File::kIsLink; |
693 } else { | 694 } else { |
694 CloseHandle(dir_handle); | 695 CloseHandle(dir_handle); |
695 result = File::kIsDirectory; | 696 result = File::kIsDirectory; |
696 } | 697 } |
697 } else { | 698 } else { |
698 result = kIsLink; | 699 result = kIsLink; |
699 } | 700 } |
700 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 701 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
701 result = kIsDirectory; | 702 result = kIsDirectory; |
702 } | 703 } |
703 return result; | 704 return result; |
704 } | 705 } |
705 | 706 |
706 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { | 707 File::Identical File::AreIdentical(Namespace* namespc, const char* file_1, const
char* file_2) { |
707 BY_HANDLE_FILE_INFORMATION file_info[2]; | 708 BY_HANDLE_FILE_INFORMATION file_info[2]; |
708 const char* file_names[2] = {file_1, file_2}; | 709 const char* file_names[2] = {file_1, file_2}; |
709 for (int i = 0; i < 2; ++i) { | 710 for (int i = 0; i < 2; ++i) { |
710 Utf8ToWideScope wide_name(file_names[i]); | 711 Utf8ToWideScope wide_name(file_names[i]); |
711 HANDLE file_handle = CreateFileW( | 712 HANDLE file_handle = CreateFileW( |
712 wide_name.wide(), 0, | 713 wide_name.wide(), 0, |
713 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 714 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
714 OPEN_EXISTING, | 715 OPEN_EXISTING, |
715 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); | 716 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); |
716 if (file_handle == INVALID_HANDLE_VALUE) { | 717 if (file_handle == INVALID_HANDLE_VALUE) { |
(...skipping 17 matching lines...) Expand all Loading... |
734 return kIdentical; | 735 return kIdentical; |
735 } else { | 736 } else { |
736 return kDifferent; | 737 return kDifferent; |
737 } | 738 } |
738 } | 739 } |
739 | 740 |
740 } // namespace bin | 741 } // namespace bin |
741 } // namespace dart | 742 } // namespace dart |
742 | 743 |
743 #endif // defined(HOST_OS_WINDOWS) | 744 #endif // defined(HOST_OS_WINDOWS) |
OLD | NEW |