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

Side by Side Diff: runtime/bin/directory_win.cc

Issue 9630012: Error reporting on File in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Style issues Created 8 years, 9 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_posix.cc ('k') | runtime/bin/file.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 "bin/directory.h" 5 #include "bin/directory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include "bin/platform.h" 10 #include "bin/platform.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 GetCurrentDirectory(length + 1, result); 331 GetCurrentDirectory(length + 1, result);
332 return result; 332 return result;
333 } 333 }
334 334
335 335
336 bool Directory::Create(const char* dir_name) { 336 bool Directory::Create(const char* dir_name) {
337 return (CreateDirectory(dir_name, NULL) != 0); 337 return (CreateDirectory(dir_name, NULL) != 0);
338 } 338 }
339 339
340 340
341 int Directory::CreateTemp(const char* const_template, 341 char* Directory::CreateTemp(const char* const_template) {
342 char** path,
343 char* os_error_message,
344 int os_error_message_len) {
345 // Returns a new, unused directory name, modifying the contents of 342 // Returns a new, unused directory name, modifying the contents of
346 // dir_template. Creates this directory, with a default security 343 // dir_template. Creates this directory, with a default security
347 // descriptor inherited from its parent directory. 344 // descriptor inherited from its parent directory.
348 // The return value must be freed by the caller. 345 // The return value must be freed by the caller.
349 *path = static_cast<char*>(malloc(MAX_PATH)); 346 char* path = static_cast<char*>(malloc(MAX_PATH));
350 int path_length; 347 int path_length;
351 if (0 == strncmp(const_template, "", 1)) { 348 if (0 == strncmp(const_template, "", 1)) {
352 path_length = GetTempPath(MAX_PATH, *path); 349 path_length = GetTempPath(MAX_PATH, path);
353 if (path_length == 0) { 350 if (path_length == 0) {
354 free(*path); 351 free(path);
355 *path = NULL; 352 return NULL;
356 int error_code =
357 SetOsErrorMessage(os_error_message, os_error_message_len);
358 return error_code;
359 } 353 }
360 } else { 354 } else {
361 snprintf(*path, MAX_PATH, "%s", const_template); 355 snprintf(path, MAX_PATH, "%s", const_template);
362 path_length = strlen(*path); 356 path_length = strlen(path);
363 } 357 }
364 // Length of tempdir-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 44. 358 // Length of tempdir-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 44.
365 if (path_length > MAX_PATH - 44) { 359 if (path_length > MAX_PATH - 44) {
366 free(*path); 360 free(path);
367 *path = NULL; 361 return NULL;
368 return -1;
369 } 362 }
370 if ((*path)[path_length - 1] == '\\') { 363 if ((path)[path_length - 1] == '\\') {
371 // No base name for the directory - use "tempdir". 364 // No base name for the directory - use "tempdir".
372 snprintf(*path + path_length, MAX_PATH - path_length, "tempdir"); 365 snprintf(path + path_length, MAX_PATH - path_length, "tempdir");
373 path_length = strlen(*path); 366 path_length = strlen(path);
374 } 367 }
375 368
376 UUID uuid; 369 UUID uuid;
377 RPC_STATUS status = UuidCreateSequential(&uuid); 370 RPC_STATUS status = UuidCreateSequential(&uuid);
378 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { 371 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
379 free(*path); 372 free(path);
380 *path = NULL; 373 return NULL;
381 int error_code =
382 SetOsErrorMessage(os_error_message, os_error_message_len);
383 return error_code;
384 } 374 }
385 RPC_CSTR uuid_string; 375 RPC_CSTR uuid_string;
386 status = UuidToString(&uuid, &uuid_string); 376 status = UuidToString(&uuid, &uuid_string);
387 if (status != RPC_S_OK) { 377 if (status != RPC_S_OK) {
388 free(*path); 378 free(path);
389 *path = NULL; 379 return NULL;
390 int error_code =
391 SetOsErrorMessage(os_error_message, os_error_message_len);
392 return error_code;
393 } 380 }
394 381
395 snprintf(*path + path_length, MAX_PATH - path_length, "-%s", uuid_string); 382 snprintf(path + path_length, MAX_PATH - path_length, "-%s", uuid_string);
396 if (!CreateDirectory(*path, NULL)) { 383 if (!CreateDirectory(path, NULL)) {
397 free(*path); 384 free(path);
398 *path = NULL; 385 return NULL;
399 int error_code =
400 SetOsErrorMessage(os_error_message, os_error_message_len);
401 return error_code;
402 } 386 }
403 return 0; 387 return path;
404 } 388 }
405 389
406 390
407 bool Directory::Delete(const char* dir_name, bool recursive) { 391 bool Directory::Delete(const char* dir_name, bool recursive) {
408 if (!recursive) { 392 if (!recursive) {
409 return (RemoveDirectory(dir_name) != 0); 393 return (RemoveDirectory(dir_name) != 0);
410 } else { 394 } else {
411 return DeleteRecursively(dir_name); 395 return DeleteRecursively(dir_name);
412 } 396 }
413 } 397 }
OLDNEW
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | runtime/bin/file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698