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

Side by Side Diff: runtime/bin/directory_linux.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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // process umask. 366 // process umask.
367 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)); 367 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777));
368 // If the directory already exists, treat it as a success. 368 // If the directory already exists, treat it as a success.
369 if (result == -1 && errno == EEXIST) { 369 if (result == -1 && errno == EEXIST) {
370 return (Exists(dir_name) == EXISTS); 370 return (Exists(dir_name) == EXISTS);
371 } 371 }
372 return (result == 0); 372 return (result == 0);
373 } 373 }
374 374
375 375
376 char* Directory::CreateTemp(const char* const_template, bool system) { 376 char* Directory::SystemTemp() {
377 // Returns a new, unused directory name, modifying the contents of 377 const char* temp_dir = getenv("TMPDIR");
378 // dir_template. Creates the directory with the permissions specified 378 if (temp_dir == NULL) {
379 temp_dir = getenv("TMP");
380 }
381 if (temp_dir == NULL) {
382 temp_dir = "/tmp";
383 }
384 int length = strnlen(temp_dir, PATH_MAX);
385 char* result = static_cast<char*>(malloc(length + 1));
386 strncpy(result, temp_dir, length);
387 result[length] = '\0';
388 return result;
389 }
390
391 char* Directory::CreateTemp(const char* prefix) {
392 // Returns a new, unused directory name, adding characters to the end
393 // of prefix. Creates the directory with the permissions specified
379 // by the process umask. 394 // by the process umask.
380 // The return value must be freed by the caller. 395 // The return value must be freed by the caller.
381 PathBuffer path; 396 PathBuffer path;
382 if (system) { 397 path.Add(prefix);
383 const char* temp_dir = getenv("TMPDIR");
384 if (temp_dir == NULL) {
385 temp_dir = getenv("TMP");
386 }
387 if (temp_dir != NULL) {
388 path.Add(temp_dir);
389 if (temp_dir[strlen(temp_dir) - 1] != '/') {
390 path.Add("/");
391 }
392 } else {
393 path.Add("/tmp/");
394 }
395 }
396 path.Add(const_template);
397 if (!path.Add("XXXXXX")) { 398 if (!path.Add("XXXXXX")) {
398 // Pattern has overflowed. 399 // Pattern has overflowed.
399 return NULL; 400 return NULL;
400 } 401 }
401 char* result; 402 char* result;
402 do { 403 do {
403 result = mkdtemp(path.AsString()); 404 result = mkdtemp(path.AsString());
404 } while (result == NULL && errno == EINTR); 405 } while (result == NULL && errno == EINTR);
405 if (result == NULL) { 406 if (result == NULL) {
406 return NULL; 407 return NULL;
(...skipping 26 matching lines...) Expand all
433 bool Directory::Rename(const char* path, const char* new_path) { 434 bool Directory::Rename(const char* path, const char* new_path) {
434 ExistsResult exists = Exists(path); 435 ExistsResult exists = Exists(path);
435 if (exists != EXISTS) return false; 436 if (exists != EXISTS) return false;
436 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 437 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
437 } 438 }
438 439
439 } // namespace bin 440 } // namespace bin
440 } // namespace dart 441 } // namespace dart
441 442
442 #endif // defined(TARGET_OS_LINUX) 443 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698