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

Side by Side Diff: runtime/bin/directory_android.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.cc ('k') | runtime/bin/directory_linux.cc » ('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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if (mktemp(path_template) == NULL) { 375 if (mktemp(path_template) == NULL) {
376 return NULL; 376 return NULL;
377 } 377 }
378 if (mkdir(path_template, 0700) != 0) { 378 if (mkdir(path_template, 0700) != 0) {
379 return NULL; 379 return NULL;
380 } 380 }
381 return path_template; 381 return path_template;
382 } 382 }
383 383
384 384
385 char* Directory::CreateTemp(const char* const_template) { 385 char* Directory::CreateTemp(const char* const_template, bool system) {
386 // Returns a new, unused directory name, modifying the contents of 386 // Returns a new, unused directory name, modifying the contents of
387 // dir_template. Creates the directory with the permissions specified 387 // dir_template. Creates the directory with the permissions specified
388 // by the process umask. 388 // by the process umask.
389 // The return value must be freed by the caller. 389 // The return value must be freed by the caller.
390 PathBuffer path; 390 PathBuffer path;
391 path.Add(const_template); 391 if (system) {
392 if (path.length() == 0) {
393 // Android does not have a /tmp directory. A partial substitute, 392 // Android does not have a /tmp directory. A partial substitute,
394 // suitable for bring-up work and tests, is to create a tmp 393 // suitable for bring-up work and tests, is to create a tmp
395 // directory in /data/local/tmp. 394 // directory in /data/local/tmp.
396 // 395 //
397 // TODO(4413): In the long run, when running in an application we should 396 // TODO(4413): In the long run, when running in an application we should
398 // probably use android.content.Context.getCacheDir(). 397 // probably use the appropriate directory from the Android API,
398 // probably what File.createTempFile uses.
399 #define ANDROID_TEMP_DIR "/data/local/tmp" 399 #define ANDROID_TEMP_DIR "/data/local/tmp"
400 struct stat st; 400 struct stat st;
401 if (stat(ANDROID_TEMP_DIR, &st) != 0) { 401 if (stat(ANDROID_TEMP_DIR, &st) != 0) {
402 mkdir(ANDROID_TEMP_DIR, 0777); 402 mkdir(ANDROID_TEMP_DIR, 0777);
403 } 403 }
404 path.Add(ANDROID_TEMP_DIR "/temp_dir1_"); 404 path.Add(ANDROID_TEMP_DIR "/");
405 } else if ((path.AsString())[path.length() - 1] == '/') {
406 path.Add("temp_dir_");
407 } 405 }
406
407 path.Add(const_template);
408 if (!path.Add("XXXXXX")) { 408 if (!path.Add("XXXXXX")) {
409 // Pattern has overflowed. 409 // Pattern has overflowed.
410 return NULL; 410 return NULL;
411 } 411 }
412
412 char* result; 413 char* result;
413 do { 414 do {
414 result = MakeTempDirectory(path.AsString()); 415 result = MakeTempDirectory(path.AsString());
415 } while (result == NULL && errno == EINTR); 416 } while (result == NULL && errno == EINTR);
416 if (result == NULL) { 417 if (result == NULL) {
417 return NULL; 418 return NULL;
418 } 419 }
419 int length = strnlen(path.AsString(), PATH_MAX); 420 int length = strnlen(path.AsString(), PATH_MAX);
420 result = static_cast<char*>(malloc(length + 1)); 421 result = static_cast<char*>(malloc(length + 1));
421 strncpy(result, path.AsString(), length); 422 strncpy(result, path.AsString(), length);
(...skipping 22 matching lines...) Expand all
444 bool Directory::Rename(const char* path, const char* new_path) { 445 bool Directory::Rename(const char* path, const char* new_path) {
445 ExistsResult exists = Exists(path); 446 ExistsResult exists = Exists(path);
446 if (exists != EXISTS) return false; 447 if (exists != EXISTS) return false;
447 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 448 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
448 } 449 }
449 450
450 } // namespace bin 451 } // namespace bin
451 } // namespace dart 452 } // namespace dart
452 453
453 #endif // defined(TARGET_OS_ANDROID) 454 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/directory.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698