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

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 deadline for removing compatibility mode. 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_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 path.Add(temp_dir);
374 if (temp_dir[strlen(temp_dir) - 1] != '/') {
375 path.Add("/");
376 }
377 } else {
378 path.Add("/tmp/");
379 }
380 }
370 path.Add(const_template); 381 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")) { 382 if (!path.Add("XXXXXX")) {
377 // Pattern has overflowed. 383 // Pattern has overflowed.
378 return NULL; 384 return NULL;
379 } 385 }
380 char* result; 386 char* result;
381 do { 387 do {
382 result = mkdtemp(path.AsString()); 388 result = mkdtemp(path.AsString());
383 } while (result == NULL && errno == EINTR); 389 } while (result == NULL && errno == EINTR);
384 if (result == NULL) { 390 if (result == NULL) {
385 return NULL; 391 return NULL;
386 } 392 }
387 int length = strlen(path.AsString()); 393 int length = strnlen(path.AsString(), PATH_MAX);
388 result = static_cast<char*>(malloc(length + 1)); 394 result = static_cast<char*>(malloc(length + 1));
389 strncpy(result, path.AsString(), length); 395 strncpy(result, path.AsString(), length);
390 result[length] = '\0'; 396 result[length] = '\0';
391 return result; 397 return result;
392 } 398 }
393 399
394 400
395 bool Directory::Delete(const char* dir_name, bool recursive) { 401 bool Directory::Delete(const char* dir_name, bool recursive) {
396 if (!recursive) { 402 if (!recursive) {
397 if (File::GetType(dir_name, false) == File::kIsLink && 403 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) { 418 bool Directory::Rename(const char* path, const char* new_path) {
413 ExistsResult exists = Exists(path); 419 ExistsResult exists = Exists(path);
414 if (exists != EXISTS) return false; 420 if (exists != EXISTS) return false;
415 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 421 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
416 } 422 }
417 423
418 } // namespace bin 424 } // namespace bin
419 } // namespace dart 425 } // namespace dart
420 426
421 #endif // defined(TARGET_OS_MACOS) 427 #endif // defined(TARGET_OS_MACOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698