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

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

Issue 28553006: dart:io | Fix File.rename on Windows to overwrite an existing target. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix previously existing problem in test. Created 7 years, 2 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
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 free(const_cast<wchar_t*>(system_name)); 284 free(const_cast<wchar_t*>(system_name));
285 return result; 285 return result;
286 } 286 }
287 287
288 288
289 bool File::Rename(const char* old_path, const char* new_path) { 289 bool File::Rename(const char* old_path, const char* new_path) {
290 File::Type type = GetType(old_path, false); 290 File::Type type = GetType(old_path, false);
291 if (type == kIsFile) { 291 if (type == kIsFile) {
292 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path); 292 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path);
293 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path); 293 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path);
294 DWORD flags = MOVEFILE_WRITE_THROUGH; 294 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING;
295 int move_status = 295 int move_status =
296 MoveFileExW(system_old_path, system_new_path, flags); 296 MoveFileExW(system_old_path, system_new_path, flags);
297 free(const_cast<wchar_t*>(system_old_path)); 297 free(const_cast<wchar_t*>(system_old_path));
298 free(const_cast<wchar_t*>(system_new_path)); 298 free(const_cast<wchar_t*>(system_new_path));
299 return (move_status != 0); 299 return (move_status != 0);
300 } else { 300 } else {
301 SetLastError(ERROR_FILE_NOT_FOUND); 301 SetLastError(ERROR_FILE_NOT_FOUND);
302 } 302 }
303 return false; 303 return false;
304 } 304 }
305 305
306 306
307 bool File::RenameLink(const char* old_path, const char* new_path) { 307 bool File::RenameLink(const char* old_path, const char* new_path) {
308 File::Type type = GetType(old_path, false); 308 File::Type type = GetType(old_path, false);
309 if (type == kIsLink) { 309 if (type == kIsLink) {
310 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path); 310 const wchar_t* system_old_path = StringUtils::Utf8ToWide(old_path);
311 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path); 311 const wchar_t* system_new_path = StringUtils::Utf8ToWide(new_path);
312 DWORD flags = MOVEFILE_WRITE_THROUGH; 312 DWORD flags = MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING;
313 int move_status = 313 int move_status =
314 MoveFileExW(system_old_path, system_new_path, flags); 314 MoveFileExW(system_old_path, system_new_path, flags);
315 free(const_cast<wchar_t*>(system_old_path)); 315 free(const_cast<wchar_t*>(system_old_path));
316 free(const_cast<wchar_t*>(system_new_path)); 316 free(const_cast<wchar_t*>(system_new_path));
317 return (move_status != 0); 317 return (move_status != 0);
318 } else { 318 } else {
319 SetLastError(ERROR_FILE_NOT_FOUND); 319 SetLastError(ERROR_FILE_NOT_FOUND);
320 } 320 }
321 return false; 321 return false;
322 } 322 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return kIdentical; 606 return kIdentical;
607 } else { 607 } else {
608 return kDifferent; 608 return kDifferent;
609 } 609 }
610 } 610 }
611 611
612 } // namespace bin 612 } // namespace bin
613 } // namespace dart 613 } // namespace dart
614 614
615 #endif // defined(TARGET_OS_WINDOWS) 615 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698