| 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, |
| 359 const char* utf8_name, |
| 360 const char* utf8_target) { |
| 358 Utf8ToWideScope name(utf8_name); | 361 Utf8ToWideScope name(utf8_name); |
| 359 int create_status = CreateDirectoryW(name.wide(), NULL); | 362 int create_status = CreateDirectoryW(name.wide(), NULL); |
| 360 // If the directory already existed, treat it as a success. | 363 // If the directory already existed, treat it as a success. |
| 361 if ((create_status == 0) && | 364 if ((create_status == 0) && |
| 362 ((GetLastError() != ERROR_ALREADY_EXISTS) || | 365 ((GetLastError() != ERROR_ALREADY_EXISTS) || |
| 363 ((GetFileAttributesW(name.wide()) & FILE_ATTRIBUTE_DIRECTORY) != 0))) { | 366 ((GetFileAttributesW(name.wide()) & FILE_ATTRIBUTE_DIRECTORY) != 0))) { |
| 364 return false; | 367 return false; |
| 365 } | 368 } |
| 366 | 369 |
| 367 HANDLE dir_handle = CreateFileW( | 370 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, | 407 dir_handle, FSCTL_SET_REPARSE_POINT, reparse_data_buffer, |
| 405 reparse_data_buffer->ReparseDataLength + kReparseDataHeaderSize, NULL, 0, | 408 reparse_data_buffer->ReparseDataLength + kReparseDataHeaderSize, NULL, 0, |
| 406 &dummy_received_bytes, NULL); | 409 &dummy_received_bytes, NULL); |
| 407 free(reparse_data_buffer); | 410 free(reparse_data_buffer); |
| 408 if (CloseHandle(dir_handle) == 0) { | 411 if (CloseHandle(dir_handle) == 0) { |
| 409 return false; | 412 return false; |
| 410 } | 413 } |
| 411 return (result != 0); | 414 return (result != 0); |
| 412 } | 415 } |
| 413 | 416 |
| 414 bool File::Delete(const char* name) { | 417 bool File::Delete(Namespace* namespc, const char* name) { |
| 415 Utf8ToWideScope system_name(name); | 418 Utf8ToWideScope system_name(name); |
| 416 int status = _wremove(system_name.wide()); | 419 int status = _wremove(system_name.wide()); |
| 417 return status != -1; | 420 return status != -1; |
| 418 } | 421 } |
| 419 | 422 |
| 420 bool File::DeleteLink(const char* name) { | 423 bool File::DeleteLink(Namespace* namespc, const char* name) { |
| 421 Utf8ToWideScope system_name(name); | 424 Utf8ToWideScope system_name(name); |
| 422 bool result = false; | 425 bool result = false; |
| 423 DWORD attributes = GetFileAttributesW(system_name.wide()); | 426 DWORD attributes = GetFileAttributesW(system_name.wide()); |
| 424 if ((attributes != INVALID_FILE_ATTRIBUTES) && | 427 if ((attributes != INVALID_FILE_ATTRIBUTES) && |
| 425 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 428 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
| 426 // It's a junction(link), delete it. | 429 // It's a junction(link), delete it. |
| 427 result = (RemoveDirectoryW(system_name.wide()) != 0); | 430 result = (RemoveDirectoryW(system_name.wide()) != 0); |
| 428 } else { | 431 } else { |
| 429 SetLastError(ERROR_NOT_A_REPARSE_POINT); | 432 SetLastError(ERROR_NOT_A_REPARSE_POINT); |
| 430 } | 433 } |
| 431 return result; | 434 return result; |
| 432 } | 435 } |
| 433 | 436 |
| 434 bool File::Rename(const char* old_path, const char* new_path) { | 437 bool File::Rename(Namespace* namespc, |
| 435 File::Type type = GetType(old_path, false); | 438 const char* old_path, |
| 439 const char* new_path) { |
| 440 File::Type type = GetType(namespc, old_path, false); |
| 436 if (type == kIsFile) { | 441 if (type == kIsFile) { |
| 437 Utf8ToWideScope system_old_path(old_path); | 442 Utf8ToWideScope system_old_path(old_path); |
| 438 Utf8ToWideScope system_new_path(new_path); | 443 Utf8ToWideScope system_new_path(new_path); |
| 439 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; | 444 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; |
| 440 int move_status = | 445 int move_status = |
| 441 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); | 446 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); |
| 442 return (move_status != 0); | 447 return (move_status != 0); |
| 443 } else { | 448 } else { |
| 444 SetLastError(ERROR_FILE_NOT_FOUND); | 449 SetLastError(ERROR_FILE_NOT_FOUND); |
| 445 } | 450 } |
| 446 return false; | 451 return false; |
| 447 } | 452 } |
| 448 | 453 |
| 449 bool File::RenameLink(const char* old_path, const char* new_path) { | 454 bool File::RenameLink(Namespace* namespc, |
| 450 File::Type type = GetType(old_path, false); | 455 const char* old_path, |
| 456 const char* new_path) { |
| 457 File::Type type = GetType(namespc, old_path, false); |
| 451 if (type == kIsLink) { | 458 if (type == kIsLink) { |
| 452 Utf8ToWideScope system_old_path(old_path); | 459 Utf8ToWideScope system_old_path(old_path); |
| 453 Utf8ToWideScope system_new_path(new_path); | 460 Utf8ToWideScope system_new_path(new_path); |
| 454 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; | 461 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING; |
| 455 int move_status = | 462 int move_status = |
| 456 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); | 463 MoveFileExW(system_old_path.wide(), system_new_path.wide(), flags); |
| 457 return (move_status != 0); | 464 return (move_status != 0); |
| 458 } else { | 465 } else { |
| 459 SetLastError(ERROR_FILE_NOT_FOUND); | 466 SetLastError(ERROR_FILE_NOT_FOUND); |
| 460 } | 467 } |
| 461 return false; | 468 return false; |
| 462 } | 469 } |
| 463 | 470 |
| 464 bool File::Copy(const char* old_path, const char* new_path) { | 471 bool File::Copy(Namespace* namespc, |
| 465 File::Type type = GetType(old_path, false); | 472 const char* old_path, |
| 473 const char* new_path) { |
| 474 File::Type type = GetType(namespc, old_path, false); |
| 466 if (type == kIsFile) { | 475 if (type == kIsFile) { |
| 467 Utf8ToWideScope system_old_path(old_path); | 476 Utf8ToWideScope system_old_path(old_path); |
| 468 Utf8ToWideScope system_new_path(new_path); | 477 Utf8ToWideScope system_new_path(new_path); |
| 469 bool success = CopyFileExW(system_old_path.wide(), system_new_path.wide(), | 478 bool success = CopyFileExW(system_old_path.wide(), system_new_path.wide(), |
| 470 NULL, NULL, NULL, 0) != 0; | 479 NULL, NULL, NULL, 0) != 0; |
| 471 return success; | 480 return success; |
| 472 } else { | 481 } else { |
| 473 SetLastError(ERROR_FILE_NOT_FOUND); | 482 SetLastError(ERROR_FILE_NOT_FOUND); |
| 474 } | 483 } |
| 475 return false; | 484 return false; |
| 476 } | 485 } |
| 477 | 486 |
| 478 int64_t File::LengthFromPath(const char* name) { | 487 int64_t File::LengthFromPath(Namespace* namespc, const char* name) { |
| 479 struct __stat64 st; | 488 struct __stat64 st; |
| 480 Utf8ToWideScope system_name(name); | 489 Utf8ToWideScope system_name(name); |
| 481 if (!StatHelper(system_name.wide(), &st)) { | 490 if (!StatHelper(system_name.wide(), &st)) { |
| 482 return -1; | 491 return -1; |
| 483 } | 492 } |
| 484 return st.st_size; | 493 return st.st_size; |
| 485 } | 494 } |
| 486 | 495 |
| 487 const char* File::LinkTarget(const char* pathname) { | 496 const char* File::LinkTarget(Namespace* namespc, const char* pathname) { |
| 488 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); | 497 const wchar_t* name = StringUtilsWin::Utf8ToWide(pathname); |
| 489 HANDLE dir_handle = CreateFileW( | 498 HANDLE dir_handle = CreateFileW( |
| 490 name, GENERIC_READ, | 499 name, GENERIC_READ, |
| 491 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 500 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
| 492 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, | 501 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, |
| 493 NULL); | 502 NULL); |
| 494 if (dir_handle == INVALID_HANDLE_VALUE) { | 503 if (dir_handle == INVALID_HANDLE_VALUE) { |
| 495 return NULL; | 504 return NULL; |
| 496 } | 505 } |
| 497 | 506 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 0, NULL, NULL); | 549 0, NULL, NULL); |
| 541 char* utf8_target = DartUtils::ScopedCString(utf8_length + 1); | 550 char* utf8_target = DartUtils::ScopedCString(utf8_length + 1); |
| 542 if (0 == WideCharToMultiByte(CP_UTF8, 0, target, target_length, utf8_target, | 551 if (0 == WideCharToMultiByte(CP_UTF8, 0, target, target_length, utf8_target, |
| 543 utf8_length, NULL, NULL)) { | 552 utf8_length, NULL, NULL)) { |
| 544 return NULL; | 553 return NULL; |
| 545 } | 554 } |
| 546 utf8_target[utf8_length] = '\0'; | 555 utf8_target[utf8_length] = '\0'; |
| 547 return utf8_target; | 556 return utf8_target; |
| 548 } | 557 } |
| 549 | 558 |
| 550 void File::Stat(const char* name, int64_t* data) { | 559 void File::Stat(Namespace* namespc, const char* name, int64_t* data) { |
| 551 File::Type type = GetType(name, false); | 560 File::Type type = GetType(namespc, name, false); |
| 552 data[kType] = type; | 561 data[kType] = type; |
| 553 if (type != kDoesNotExist) { | 562 if (type != kDoesNotExist) { |
| 554 struct _stat64 st; | 563 struct _stat64 st; |
| 555 Utf8ToWideScope system_name(name); | 564 Utf8ToWideScope system_name(name); |
| 556 int stat_status = _wstat64(system_name.wide(), &st); | 565 int stat_status = _wstat64(system_name.wide(), &st); |
| 557 if (stat_status == 0) { | 566 if (stat_status == 0) { |
| 558 data[kCreatedTime] = st.st_ctime * 1000; | 567 data[kCreatedTime] = st.st_ctime * 1000; |
| 559 data[kModifiedTime] = st.st_mtime * 1000; | 568 data[kModifiedTime] = st.st_mtime * 1000; |
| 560 data[kAccessedTime] = st.st_atime * 1000; | 569 data[kAccessedTime] = st.st_atime * 1000; |
| 561 data[kMode] = st.st_mode; | 570 data[kMode] = st.st_mode; |
| 562 data[kSize] = st.st_size; | 571 data[kSize] = st.st_size; |
| 563 } else { | 572 } else { |
| 564 data[kType] = File::kDoesNotExist; | 573 data[kType] = File::kDoesNotExist; |
| 565 } | 574 } |
| 566 } | 575 } |
| 567 } | 576 } |
| 568 | 577 |
| 569 time_t File::LastAccessed(const char* name) { | 578 time_t File::LastAccessed(Namespace* namespc, const char* name) { |
| 570 struct __stat64 st; | 579 struct __stat64 st; |
| 571 Utf8ToWideScope system_name(name); | 580 Utf8ToWideScope system_name(name); |
| 572 if (!StatHelper(system_name.wide(), &st)) { | 581 if (!StatHelper(system_name.wide(), &st)) { |
| 573 return -1; | 582 return -1; |
| 574 } | 583 } |
| 575 return st.st_atime; | 584 return st.st_atime; |
| 576 } | 585 } |
| 577 | 586 |
| 578 time_t File::LastModified(const char* name) { | 587 time_t File::LastModified(Namespace* namespc, const char* name) { |
| 579 struct __stat64 st; | 588 struct __stat64 st; |
| 580 Utf8ToWideScope system_name(name); | 589 Utf8ToWideScope system_name(name); |
| 581 if (!StatHelper(system_name.wide(), &st)) { | 590 if (!StatHelper(system_name.wide(), &st)) { |
| 582 return -1; | 591 return -1; |
| 583 } | 592 } |
| 584 return st.st_mtime; | 593 return st.st_mtime; |
| 585 } | 594 } |
| 586 | 595 |
| 587 bool File::SetLastAccessed(const char* name, int64_t millis) { | 596 bool File::SetLastAccessed(Namespace* namespc, |
| 597 const char* name, |
| 598 int64_t millis) { |
| 588 // First get the current times. | 599 // First get the current times. |
| 589 struct __stat64 st; | 600 struct __stat64 st; |
| 590 Utf8ToWideScope system_name(name); | 601 Utf8ToWideScope system_name(name); |
| 591 if (!StatHelper(system_name.wide(), &st)) { | 602 if (!StatHelper(system_name.wide(), &st)) { |
| 592 return false; | 603 return false; |
| 593 } | 604 } |
| 594 | 605 |
| 595 // Set the new time: | 606 // Set the new time: |
| 596 struct __utimbuf64 times; | 607 struct __utimbuf64 times; |
| 597 times.actime = millis / kMillisecondsPerSecond; | 608 times.actime = millis / kMillisecondsPerSecond; |
| 598 times.modtime = st.st_mtime; | 609 times.modtime = st.st_mtime; |
| 599 return _wutime64(system_name.wide(), ×) == 0; | 610 return _wutime64(system_name.wide(), ×) == 0; |
| 600 } | 611 } |
| 601 | 612 |
| 602 bool File::SetLastModified(const char* name, int64_t millis) { | 613 bool File::SetLastModified(Namespace* namespc, |
| 614 const char* name, |
| 615 int64_t millis) { |
| 603 // First get the current times. | 616 // First get the current times. |
| 604 struct __stat64 st; | 617 struct __stat64 st; |
| 605 Utf8ToWideScope system_name(name); | 618 Utf8ToWideScope system_name(name); |
| 606 if (!StatHelper(system_name.wide(), &st)) { | 619 if (!StatHelper(system_name.wide(), &st)) { |
| 607 return false; | 620 return false; |
| 608 } | 621 } |
| 609 | 622 |
| 610 // Set the new time: | 623 // Set the new time: |
| 611 struct __utimbuf64 times; | 624 struct __utimbuf64 times; |
| 612 times.actime = st.st_atime; | 625 times.actime = st.st_atime; |
| 613 times.modtime = millis / kMillisecondsPerSecond; | 626 times.modtime = millis / kMillisecondsPerSecond; |
| 614 return _wutime64(system_name.wide(), ×) == 0; | 627 return _wutime64(system_name.wide(), ×) == 0; |
| 615 } | 628 } |
| 616 | 629 |
| 617 bool File::IsAbsolutePath(const char* pathname) { | 630 bool File::IsAbsolutePath(const char* pathname) { |
| 618 // Should we consider network paths? | 631 // Should we consider network paths? |
| 619 if (pathname == NULL) { | 632 if (pathname == NULL) { |
| 620 return false; | 633 return false; |
| 621 } | 634 } |
| 622 return ((strlen(pathname) > 2) && (pathname[1] == ':') && | 635 return ((strlen(pathname) > 2) && (pathname[1] == ':') && |
| 623 ((pathname[2] == '\\') || (pathname[2] == '/'))); | 636 ((pathname[2] == '\\') || (pathname[2] == '/'))); |
| 624 } | 637 } |
| 625 | 638 |
| 626 const char* File::GetCanonicalPath(const char* pathname) { | 639 const char* File::GetCanonicalPath(Namespace* namespc, const char* pathname) { |
| 627 Utf8ToWideScope system_name(pathname); | 640 Utf8ToWideScope system_name(pathname); |
| 628 HANDLE file_handle = | 641 HANDLE file_handle = |
| 629 CreateFileW(system_name.wide(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, | 642 CreateFileW(system_name.wide(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
| 630 FILE_FLAG_BACKUP_SEMANTICS, NULL); | 643 FILE_FLAG_BACKUP_SEMANTICS, NULL); |
| 631 if (file_handle == INVALID_HANDLE_VALUE) { | 644 if (file_handle == INVALID_HANDLE_VALUE) { |
| 632 return NULL; | 645 return NULL; |
| 633 } | 646 } |
| 634 wchar_t dummy_buffer[1]; | 647 wchar_t dummy_buffer[1]; |
| 635 int required_size = | 648 int required_size = |
| 636 GetFinalPathNameByHandle(file_handle, dummy_buffer, 0, VOLUME_NAME_DOS); | 649 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. | 681 // This is already UTF-8 encoded. |
| 669 return "\\\\"; | 682 return "\\\\"; |
| 670 } | 683 } |
| 671 | 684 |
| 672 File::StdioHandleType File::GetStdioHandleType(int fd) { | 685 File::StdioHandleType File::GetStdioHandleType(int fd) { |
| 673 // Treat all stdio handles as pipes. The Windows event handler and | 686 // Treat all stdio handles as pipes. The Windows event handler and |
| 674 // socket code will handle the different handle types. | 687 // socket code will handle the different handle types. |
| 675 return kPipe; | 688 return kPipe; |
| 676 } | 689 } |
| 677 | 690 |
| 678 File::Type File::GetType(const char* pathname, bool follow_links) { | 691 File::Type File::GetType(Namespace* namespc, |
| 692 const char* pathname, |
| 693 bool follow_links) { |
| 679 // Convert to wchar_t string. | 694 // Convert to wchar_t string. |
| 680 Utf8ToWideScope name(pathname); | 695 Utf8ToWideScope name(pathname); |
| 681 DWORD attributes = GetFileAttributesW(name.wide()); | 696 DWORD attributes = GetFileAttributesW(name.wide()); |
| 682 File::Type result = kIsFile; | 697 File::Type result = kIsFile; |
| 683 if (attributes == INVALID_FILE_ATTRIBUTES) { | 698 if (attributes == INVALID_FILE_ATTRIBUTES) { |
| 684 result = kDoesNotExist; | 699 result = kDoesNotExist; |
| 685 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | 700 } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { |
| 686 if (follow_links) { | 701 if (follow_links) { |
| 687 HANDLE dir_handle = | 702 HANDLE dir_handle = |
| 688 CreateFileW(name.wide(), 0, | 703 CreateFileW(name.wide(), 0, |
| 689 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 704 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 690 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 705 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
| 691 if (dir_handle == INVALID_HANDLE_VALUE) { | 706 if (dir_handle == INVALID_HANDLE_VALUE) { |
| 692 result = File::kIsLink; | 707 result = File::kIsLink; |
| 693 } else { | 708 } else { |
| 694 CloseHandle(dir_handle); | 709 CloseHandle(dir_handle); |
| 695 result = File::kIsDirectory; | 710 result = File::kIsDirectory; |
| 696 } | 711 } |
| 697 } else { | 712 } else { |
| 698 result = kIsLink; | 713 result = kIsLink; |
| 699 } | 714 } |
| 700 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 715 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
| 701 result = kIsDirectory; | 716 result = kIsDirectory; |
| 702 } | 717 } |
| 703 return result; | 718 return result; |
| 704 } | 719 } |
| 705 | 720 |
| 706 File::Identical File::AreIdentical(const char* file_1, const char* file_2) { | 721 File::Identical File::AreIdentical(Namespace* namespc, |
| 722 const char* file_1, |
| 723 const char* file_2) { |
| 707 BY_HANDLE_FILE_INFORMATION file_info[2]; | 724 BY_HANDLE_FILE_INFORMATION file_info[2]; |
| 708 const char* file_names[2] = {file_1, file_2}; | 725 const char* file_names[2] = {file_1, file_2}; |
| 709 for (int i = 0; i < 2; ++i) { | 726 for (int i = 0; i < 2; ++i) { |
| 710 Utf8ToWideScope wide_name(file_names[i]); | 727 Utf8ToWideScope wide_name(file_names[i]); |
| 711 HANDLE file_handle = CreateFileW( | 728 HANDLE file_handle = CreateFileW( |
| 712 wide_name.wide(), 0, | 729 wide_name.wide(), 0, |
| 713 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 730 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
| 714 OPEN_EXISTING, | 731 OPEN_EXISTING, |
| 715 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); | 732 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); |
| 716 if (file_handle == INVALID_HANDLE_VALUE) { | 733 if (file_handle == INVALID_HANDLE_VALUE) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 734 return kIdentical; | 751 return kIdentical; |
| 735 } else { | 752 } else { |
| 736 return kDifferent; | 753 return kDifferent; |
| 737 } | 754 } |
| 738 } | 755 } |
| 739 | 756 |
| 740 } // namespace bin | 757 } // namespace bin |
| 741 } // namespace dart | 758 } // namespace dart |
| 742 | 759 |
| 743 #endif // defined(HOST_OS_WINDOWS) | 760 #endif // defined(HOST_OS_WINDOWS) |
| OLD | NEW |