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

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

Issue 860343002: Fix issue with Link.target and Link.targetSync failing on some file systems (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 5 years, 11 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 | « no previous file | runtime/bin/file_macos.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_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/file.h" 8 #include "bin/file.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 361 }
362 362
363 363
364 char* File::LinkTarget(const char* pathname) { 364 char* File::LinkTarget(const char* pathname) {
365 struct stat64 link_stats; 365 struct stat64 link_stats;
366 if (TEMP_FAILURE_RETRY(lstat64(pathname, &link_stats)) != 0) return NULL; 366 if (TEMP_FAILURE_RETRY(lstat64(pathname, &link_stats)) != 0) return NULL;
367 if (!S_ISLNK(link_stats.st_mode)) { 367 if (!S_ISLNK(link_stats.st_mode)) {
368 errno = ENOENT; 368 errno = ENOENT;
369 return NULL; 369 return NULL;
370 } 370 }
371 size_t target_size = link_stats.st_size; 371 // Don't rely on the link_stats.st_size for the size of the link
372 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); 372 // target. For some filesystems, e.g. procfs, this value is always
373 size_t read_size = NO_RETRY_EXPECTED( 373 // 0. Also the link might have changed before the readlink call.
374 readlink(pathname, target_name, target_size + 1)); 374 const int kBufferSize = PATH_MAX + 1;
375 if (read_size != target_size) { 375 char target[kBufferSize];
376 free(target_name); 376 size_t target_size = TEMP_FAILURE_RETRY(
377 readlink(pathname, target, kBufferSize));
378 if (target_size <= 0) {
377 return NULL; 379 return NULL;
378 } 380 }
381 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
382 if (target_name == NULL) {
383 return NULL;
384 }
385 memmove(target_name, target, target_size);
379 target_name[target_size] = '\0'; 386 target_name[target_size] = '\0';
380 return target_name; 387 return target_name;
381 } 388 }
382 389
383 390
384 bool File::IsAbsolutePath(const char* pathname) { 391 bool File::IsAbsolutePath(const char* pathname) {
385 return (pathname != NULL && pathname[0] == '/'); 392 return (pathname != NULL && pathname[0] == '/');
386 } 393 }
387 394
388 395
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 return (file_1_info.st_ino == file_2_info.st_ino && 459 return (file_1_info.st_ino == file_2_info.st_ino &&
453 file_1_info.st_dev == file_2_info.st_dev) ? 460 file_1_info.st_dev == file_2_info.st_dev) ?
454 File::kIdentical : 461 File::kIdentical :
455 File::kDifferent; 462 File::kDifferent;
456 } 463 }
457 464
458 } // namespace bin 465 } // namespace bin
459 } // namespace dart 466 } // namespace dart
460 467
461 #endif // defined(TARGET_OS_LINUX) 468 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/file_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698