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

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

Issue 12850010: Add FileSystemEntity.identical, to test if two file system objects are the same. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve posix versions Created 7 years, 9 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 return File::kDoesNotExist; 507 return File::kDoesNotExist;
508 } 508 }
509 } 509 }
510 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { 510 } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
511 return File::kIsDirectory; 511 return File::kIsDirectory;
512 } else { 512 } else {
513 return File::kIsFile; 513 return File::kIsFile;
514 } 514 }
515 } 515 }
516 516
517
518 File::Identical File::AreIdentical(const char* file_1, const char* file_2) {
519 BY_HANDLE_FILE_INFORMATION file_info[2];
520 const char* file_names[2] = { file_1, file_2 };
521 for (int i = 0; i < 2; ++i) {
522 const wchar_t* wide_name = StringUtils::Utf8ToWide(file_names[i]);
523 HANDLE file_handle = CreateFileW(
524 wide_name,
525 0,
526 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
527 NULL,
528 OPEN_EXISTING,
529 FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
530 NULL);
531 if (file_handle == INVALID_HANDLE_VALUE) {
532 DWORD error = GetLastError();
533 free(const_cast<wchar_t*>(wide_name));
534 SetLastError(error);
535 return File::kError;
536 }
537 free(const_cast<wchar_t*>(wide_name));
538 int result = GetFileInformationByHandle(file_handle, &file_info[i]);
539 if (result == 0) {
540 DWORD error = GetLastError();
541 CloseHandle(file_handle);
542 SetLastError(error);
543 return File::kError;
544 }
545 if (CloseHandle(file_handle) == 0) {
546 return File::kError;
547 }
548 }
549 if (file_info[0].dwVolumeSerialNumber == file_info[1].dwVolumeSerialNumber &&
550 file_info[0].nFileIndexHigh == file_info[1].nFileIndexHigh &&
551 file_info[0].nFileIndexLow == file_info[1].nFileIndexLow) {
552 return kIdentical;
553 } else {
554 return kDifferent;
555 }
556 }
557
517 #endif // defined(TARGET_OS_WINDOWS) 558 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698