Chromium Code Reviews| 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"); | |
|
Søren Gjesse
2013/10/01 14:28:47
Should we check TMP as well?
| |
| 384 if (temp_dir != NULL) { | |
| 385 path.Add(temp_dir); | |
| 386 if (temp_dir[strlen(temp_dir) - 1] != '/') { | |
| 387 path.Add("/"); | |
| 388 } | |
| 389 } else { | |
| 390 path.Add("/tmp/"); | |
| 391 } | |
| 392 } | |
| 381 path.Add(const_template); | 393 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")) { | 394 if (!path.Add("XXXXXX")) { |
| 388 // Pattern has overflowed. | 395 // Pattern has overflowed. |
| 389 return NULL; | 396 return NULL; |
| 390 } | 397 } |
| 391 char* result; | 398 char* result; |
| 392 do { | 399 do { |
| 393 result = mkdtemp(path.AsString()); | 400 result = mkdtemp(path.AsString()); |
| 394 } while (result == NULL && errno == EINTR); | 401 } while (result == NULL && errno == EINTR); |
| 395 if (result == NULL) { | 402 if (result == NULL) { |
| 396 return NULL; | 403 return NULL; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 423 bool Directory::Rename(const char* path, const char* new_path) { | 430 bool Directory::Rename(const char* path, const char* new_path) { |
| 424 ExistsResult exists = Exists(path); | 431 ExistsResult exists = Exists(path); |
| 425 if (exists != EXISTS) return false; | 432 if (exists != EXISTS) return false; |
| 426 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 433 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 427 } | 434 } |
| 428 | 435 |
| 429 } // namespace bin | 436 } // namespace bin |
| 430 } // namespace dart | 437 } // namespace dart |
| 431 | 438 |
| 432 #endif // defined(TARGET_OS_LINUX) | 439 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |