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

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

Issue 11175054: Change Directory.create to not fail on existing directory with that name. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 8 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 | « runtime/bin/directory_macos.cc ('k') | tests/standalone/io/directory_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 "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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 char* Directory::Current() { 341 char* Directory::Current() {
342 char* result; 342 char* result;
343 int length = GetCurrentDirectory(0, NULL); 343 int length = GetCurrentDirectory(0, NULL);
344 result = reinterpret_cast<char*>(malloc(length + 1)); 344 result = reinterpret_cast<char*>(malloc(length + 1));
345 GetCurrentDirectory(length + 1, result); 345 GetCurrentDirectory(length + 1, result);
346 return result; 346 return result;
347 } 347 }
348 348
349 349
350 bool Directory::Create(const char* dir_name) { 350 bool Directory::Create(const char* dir_name) {
351 // If the directory already exists and is a directory do not
352 // attempt to create it again and treat it as a success.
353 if (Exists(dir_name) == EXISTS) return true;
351 return (CreateDirectory(dir_name, NULL) != 0); 354 return (CreateDirectory(dir_name, NULL) != 0);
352 } 355 }
353 356
354 357
355 char* Directory::CreateTemp(const char* const_template) { 358 char* Directory::CreateTemp(const char* const_template) {
356 // Returns a new, unused directory name, modifying the contents of 359 // Returns a new, unused directory name, modifying the contents of
357 // dir_template. Creates this directory, with a default security 360 // dir_template. Creates this directory, with a default security
358 // descriptor inherited from its parent directory. 361 // descriptor inherited from its parent directory.
359 // The return value must be freed by the caller. 362 // The return value must be freed by the caller.
360 char* path = static_cast<char*>(malloc(MAX_PATH)); 363 char* path = static_cast<char*>(malloc(MAX_PATH));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // MoveFile does not allow replacing exising directories. Therefore, 421 // MoveFile does not allow replacing exising directories. Therefore,
419 // if the new_path is currently a directory we need to delete it 422 // if the new_path is currently a directory we need to delete it
420 // first. 423 // first.
421 if (new_exists == EXISTS) { 424 if (new_exists == EXISTS) {
422 bool success = DeleteRecursively(new_path); 425 bool success = DeleteRecursively(new_path);
423 if (!success) return false; 426 if (!success) return false;
424 } 427 }
425 DWORD flags = MOVEFILE_WRITE_THROUGH; 428 DWORD flags = MOVEFILE_WRITE_THROUGH;
426 return (MoveFileEx(path, new_path, flags) != 0); 429 return (MoveFileEx(path, new_path, flags) != 0);
427 } 430 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | tests/standalone/io/directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698