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

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

Issue 25720002: Add Directory.systemTemp getter to replace createSystemTemp(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't add an extra / to a directory ending in // 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 | « runtime/bin/directory_linux.cc ('k') | runtime/bin/directory_patch.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_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 9
10 #include <dirent.h> // NOLINT 10 #include <dirent.h> // NOLINT
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // process umask. 354 // process umask.
355 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)); 355 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777));
356 // If the directory already exists, treat it as a success. 356 // If the directory already exists, treat it as a success.
357 if (result == -1 && errno == EEXIST) { 357 if (result == -1 && errno == EEXIST) {
358 return (Exists(dir_name) == EXISTS); 358 return (Exists(dir_name) == EXISTS);
359 } 359 }
360 return (result == 0); 360 return (result == 0);
361 } 361 }
362 362
363 363
364 char* Directory::CreateTemp(const char* const_template, bool system) { 364 char* Directory::SystemTemp() {
365 // Returns a new, unused directory name, modifying the contents of 365 const char* temp_dir = getenv("TMPDIR");
366 // dir_template. Creates the directory with the permissions specified 366 if (temp_dir == NULL) {
367 temp_dir = getenv("TMP");
368 }
369 if (temp_dir == NULL) {
370 temp_dir = "/tmp";
371 }
372 return strdup(temp_dir);
373 }
374
375
376 char* Directory::CreateTemp(const char* prefix) {
377 // Returns a new, unused directory name, adding characters to the end
378 // of prefix. Creates the directory with the permissions specified
367 // by the process umask. 379 // by the process umask.
368 // The return value must be freed by the caller. 380 // The return value must be freed by the caller.
369 PathBuffer path; 381 PathBuffer path;
370 if (system) { 382 path.Add(prefix);
371 const char* temp_dir = getenv("TMPDIR");
372 if (temp_dir == NULL) {
373 temp_dir = getenv("TMP");
374 }
375 if (temp_dir != NULL) {
376 path.Add(temp_dir);
377 if (temp_dir[strlen(temp_dir) - 1] != '/') {
378 path.Add("/");
379 }
380 } else {
381 path.Add("/tmp/");
382 }
383 }
384 path.Add(const_template);
385 if (!path.Add("XXXXXX")) { 383 if (!path.Add("XXXXXX")) {
386 // Pattern has overflowed. 384 // Pattern has overflowed.
387 return NULL; 385 return NULL;
388 } 386 }
389 char* result; 387 char* result;
390 do { 388 do {
391 result = mkdtemp(path.AsString()); 389 result = mkdtemp(path.AsString());
392 } while (result == NULL && errno == EINTR); 390 } while (result == NULL && errno == EINTR);
393 if (result == NULL) { 391 if (result == NULL) {
394 return NULL; 392 return NULL;
395 } 393 }
396 int length = strlen(path.AsString()); 394 return strdup(result);
397 result = static_cast<char*>(malloc(length + 1));
398 strncpy(result, path.AsString(), length);
399 result[length] = '\0';
400 return result;
401 } 395 }
402 396
403 397
404 bool Directory::Delete(const char* dir_name, bool recursive) { 398 bool Directory::Delete(const char* dir_name, bool recursive) {
405 if (!recursive) { 399 if (!recursive) {
406 if (File::GetType(dir_name, false) == File::kIsLink && 400 if (File::GetType(dir_name, false) == File::kIsLink &&
407 File::GetType(dir_name, true) == File::kIsDirectory) { 401 File::GetType(dir_name, true) == File::kIsDirectory) {
408 return (TEMP_FAILURE_RETRY(unlink(dir_name)) == 0); 402 return (TEMP_FAILURE_RETRY(unlink(dir_name)) == 0);
409 } 403 }
410 return (TEMP_FAILURE_RETRY(rmdir(dir_name)) == 0); 404 return (TEMP_FAILURE_RETRY(rmdir(dir_name)) == 0);
(...skipping 10 matching lines...) Expand all
421 bool Directory::Rename(const char* path, const char* new_path) { 415 bool Directory::Rename(const char* path, const char* new_path) {
422 ExistsResult exists = Exists(path); 416 ExistsResult exists = Exists(path);
423 if (exists != EXISTS) return false; 417 if (exists != EXISTS) return false;
424 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 418 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
425 } 419 }
426 420
427 } // namespace bin 421 } // namespace bin
428 } // namespace dart 422 } // namespace dart
429 423
430 #endif // defined(TARGET_OS_MACOS) 424 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/directory_linux.cc ('k') | runtime/bin/directory_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698