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

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

Issue 25720002: Add Directory.systemTemp getter to replace createSystemTemp(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add dart2js patch files. 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
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/directory.h" 8 #include "bin/directory.h"
9 #include "bin/file.h" 9 #include "bin/file.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 GetLastError() == ERROR_ALREADY_EXISTS && 376 GetLastError() == ERROR_ALREADY_EXISTS &&
377 ExistsHelper(system_name) == EXISTS) { 377 ExistsHelper(system_name) == EXISTS) {
378 free(const_cast<wchar_t*>(system_name)); 378 free(const_cast<wchar_t*>(system_name));
379 return true; 379 return true;
380 } 380 }
381 free(const_cast<wchar_t*>(system_name)); 381 free(const_cast<wchar_t*>(system_name));
382 return (create_status != 0); 382 return (create_status != 0);
383 } 383 }
384 384
385 385
386 char* Directory::CreateTemp(const char* const_template, bool system) { 386 char* Directory::SystemTemp() {
387 // Returns a new, unused directory name, modifying the contents of 387 PathBuffer path;
388 // dir_template. Creates this directory, with a default security 388 path.Reset(GetTempPathW(MAX_PATH, path.AsStringW()) - 1); // Remove \ at end.
389 return path.AsString();
390 }
391
392 char* Directory::CreateTemp(const char* prefix) {
393 // Returns a new, unused directory name, adding characters to the
394 // end of prefix.
395 // Creates this directory, with a default security
389 // descriptor inherited from its parent directory. 396 // descriptor inherited from its parent directory.
390 // The return value must be freed by the caller. 397 // The return value must be freed by the caller.
391 PathBuffer path; 398 PathBuffer path;
392 if (system) { 399 const wchar_t* system_prefix = StringUtils::Utf8ToWide(prefix);
393 path.Reset(GetTempPathW(MAX_PATH, path.AsStringW())); 400 path.AddW(system_prefix);
394 if (path.length() == 0) { 401 free(const_cast<wchar_t*>(system_prefix));
395 return NULL;
396 }
397 }
398 const wchar_t* system_template = StringUtils::Utf8ToWide(const_template);
399 path.AddW(system_template);
400 free(const_cast<wchar_t*>(system_template));
401 402
402 // Length of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 36. 403 // Length of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 36.
403 if (path.length() > MAX_PATH - 36) { 404 if (path.length() > MAX_PATH - 36) {
404 return NULL; 405 return NULL;
405 } 406 }
406 407
407 UUID uuid; 408 UUID uuid;
408 RPC_STATUS status = UuidCreateSequential(&uuid); 409 RPC_STATUS status = UuidCreateSequential(&uuid);
409 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { 410 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
410 return NULL; 411 return NULL;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 MoveFileExW(system_path, system_new_path, flags); 465 MoveFileExW(system_path, system_new_path, flags);
465 free(const_cast<wchar_t*>(system_path)); 466 free(const_cast<wchar_t*>(system_path));
466 free(const_cast<wchar_t*>(system_new_path)); 467 free(const_cast<wchar_t*>(system_new_path));
467 return (move_status != 0); 468 return (move_status != 0);
468 } 469 }
469 470
470 } // namespace bin 471 } // namespace bin
471 } // namespace dart 472 } // namespace dart
472 473
473 #endif // defined(TARGET_OS_WINDOWS) 474 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698