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 "bin/directory.h" | 5 #include "bin/directory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include "bin/platform.h" | 10 #include "bin/platform.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 375 } |
376 | 376 |
377 | 377 |
378 bool Directory::Delete(const char* dir_name, bool recursive) { | 378 bool Directory::Delete(const char* dir_name, bool recursive) { |
379 if (!recursive) { | 379 if (!recursive) { |
380 return (RemoveDirectory(dir_name) != 0); | 380 return (RemoveDirectory(dir_name) != 0); |
381 } else { | 381 } else { |
382 return DeleteRecursively(dir_name); | 382 return DeleteRecursively(dir_name); |
383 } | 383 } |
384 } | 384 } |
| 385 |
| 386 |
| 387 bool Directory::Rename(const char* path, const char* new_path) { |
| 388 ExistsResult exists = Exists(path); |
| 389 if (exists != EXISTS) return false; |
| 390 ExistsResult new_exists = Exists(new_path); |
| 391 // MoveFile does not allow replacing exising directories. Therefore, |
| 392 // if the new_path is currently a directory we need to delete it |
| 393 // first. |
| 394 if (new_exists == EXISTS) { |
| 395 bool success = DeleteRecursively(new_path); |
| 396 if (!success) return false; |
| 397 } |
| 398 DWORD flags = MOVEFILE_WRITE_THROUGH; |
| 399 return (MoveFileEx(path, new_path, flags) != 0); |
| 400 } |
OLD | NEW |