| OLD | NEW |
| 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 |
| 11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 12 #include <stdlib.h> // NOLINT |
| 12 #include <string.h> // NOLINT | 13 #include <string.h> // NOLINT |
| 13 #include <sys/param.h> // NOLINT | 14 #include <sys/param.h> // NOLINT |
| 14 #include <sys/stat.h> // NOLINT | 15 #include <sys/stat.h> // NOLINT |
| 15 #include <unistd.h> // NOLINT | 16 #include <unistd.h> // NOLINT |
| 16 | 17 |
| 17 #include "bin/file.h" | 18 #include "bin/file.h" |
| 18 #include "bin/platform.h" | 19 #include "bin/platform.h" |
| 19 | 20 |
| 20 | 21 |
| 21 namespace dart { | 22 namespace dart { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // process umask. | 366 // process umask. |
| 366 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)); | 367 int result = TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)); |
| 367 // If the directory already exists, treat it as a success. | 368 // If the directory already exists, treat it as a success. |
| 368 if (result == -1 && errno == EEXIST) { | 369 if (result == -1 && errno == EEXIST) { |
| 369 return (Exists(dir_name) == EXISTS); | 370 return (Exists(dir_name) == EXISTS); |
| 370 } | 371 } |
| 371 return (result == 0); | 372 return (result == 0); |
| 372 } | 373 } |
| 373 | 374 |
| 374 | 375 |
| 375 char* Directory::CreateTemp(const char* const_template) { | 376 char* Directory::CreateTemp(const char* const_template, bool system) { |
| 376 // Returns a new, unused directory name, modifying the contents of | 377 // Returns a new, unused directory name, modifying the contents of |
| 377 // dir_template. Creates the directory with the permissions specified | 378 // dir_template. Creates the directory with the permissions specified |
| 378 // by the process umask. | 379 // by the process umask. |
| 379 // The return value must be freed by the caller. | 380 // The return value must be freed by the caller. |
| 380 PathBuffer path; | 381 PathBuffer path; |
| 382 if (system) { |
| 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 } |
| 381 path.Add(const_template); | 396 path.Add(const_template); |
| 382 if (path.length() == 0) { | |
| 383 path.Add("/tmp/temp_dir1_"); | |
| 384 } else if ((path.AsString())[path.length() - 1] == '/') { | |
| 385 path.Add("temp_dir_"); | |
| 386 } | |
| 387 if (!path.Add("XXXXXX")) { | 397 if (!path.Add("XXXXXX")) { |
| 388 // Pattern has overflowed. | 398 // Pattern has overflowed. |
| 389 return NULL; | 399 return NULL; |
| 390 } | 400 } |
| 391 char* result; | 401 char* result; |
| 392 do { | 402 do { |
| 393 result = mkdtemp(path.AsString()); | 403 result = mkdtemp(path.AsString()); |
| 394 } while (result == NULL && errno == EINTR); | 404 } while (result == NULL && errno == EINTR); |
| 395 if (result == NULL) { | 405 if (result == NULL) { |
| 396 return NULL; | 406 return NULL; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 423 bool Directory::Rename(const char* path, const char* new_path) { | 433 bool Directory::Rename(const char* path, const char* new_path) { |
| 424 ExistsResult exists = Exists(path); | 434 ExistsResult exists = Exists(path); |
| 425 if (exists != EXISTS) return false; | 435 if (exists != EXISTS) return false; |
| 426 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 436 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 427 } | 437 } |
| 428 | 438 |
| 429 } // namespace bin | 439 } // namespace bin |
| 430 } // namespace dart | 440 } // namespace dart |
| 431 | 441 |
| 432 #endif // defined(TARGET_OS_LINUX) | 442 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |