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

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

Issue 25279003: dart:io | Add Directory.CreateSystemTemp(template) and change Directory.CreateTemp(template). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add check of "TMP" environment variable if "TMPDIR" is missing. 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) { 364 char* Directory::CreateTemp(const char* const_template, bool system) {
365 // Returns a new, unused directory name, modifying the contents of 365 // Returns a new, unused directory name, modifying the contents of
366 // dir_template. Creates the directory with the permissions specified 366 // dir_template. Creates the directory with the permissions specified
367 // by the process umask. 367 // by the process umask.
368 // The return value must be freed by the caller. 368 // The return value must be freed by the caller.
369 PathBuffer path; 369 PathBuffer path;
370 if (system) {
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 }
370 path.Add(const_template); 384 path.Add(const_template);
371 if (path.length() == 0) {
372 path.Add("/tmp/temp_dir1_");
373 } else if ((path.AsString())[path.length() - 1] == '/') {
374 path.Add("temp_dir_");
375 }
376 if (!path.Add("XXXXXX")) { 385 if (!path.Add("XXXXXX")) {
377 // Pattern has overflowed. 386 // Pattern has overflowed.
378 return NULL; 387 return NULL;
379 } 388 }
380 char* result; 389 char* result;
381 do { 390 do {
382 result = mkdtemp(path.AsString()); 391 result = mkdtemp(path.AsString());
383 } while (result == NULL && errno == EINTR); 392 } while (result == NULL && errno == EINTR);
384 if (result == NULL) { 393 if (result == NULL) {
385 return NULL; 394 return NULL;
386 } 395 }
387 int length = strlen(path.AsString()); 396 int length = strnlen(path.AsString(), PATH_MAX);
388 result = static_cast<char*>(malloc(length + 1)); 397 result = static_cast<char*>(malloc(length + 1));
389 strncpy(result, path.AsString(), length); 398 strncpy(result, path.AsString(), length);
390 result[length] = '\0'; 399 result[length] = '\0';
391 return result; 400 return result;
392 } 401 }
393 402
394 403
395 bool Directory::Delete(const char* dir_name, bool recursive) { 404 bool Directory::Delete(const char* dir_name, bool recursive) {
396 if (!recursive) { 405 if (!recursive) {
397 if (File::GetType(dir_name, false) == File::kIsLink && 406 if (File::GetType(dir_name, false) == File::kIsLink &&
(...skipping 14 matching lines...) Expand all
412 bool Directory::Rename(const char* path, const char* new_path) { 421 bool Directory::Rename(const char* path, const char* new_path) {
413 ExistsResult exists = Exists(path); 422 ExistsResult exists = Exists(path);
414 if (exists != EXISTS) return false; 423 if (exists != EXISTS) return false;
415 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 424 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
416 } 425 }
417 426
418 } // namespace bin 427 } // namespace bin
419 } // namespace dart 428 } // namespace dart
420 429
421 #endif // defined(TARGET_OS_MACOS) 430 #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