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

Side by Side Diff: base/file_util_posix.cc

Issue 5349007: Some additions to support symlinks better on platforms that support them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removing TODO Created 10 years 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 | « base/file_util.h ('k') | base/file_util_unittest.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 while (total_read < bytes) { 366 while (total_read < bytes) {
367 ssize_t bytes_read = 367 ssize_t bytes_read =
368 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read)); 368 HANDLE_EINTR(read(fd, buffer + total_read, bytes - total_read));
369 if (bytes_read <= 0) 369 if (bytes_read <= 0)
370 break; 370 break;
371 total_read += bytes_read; 371 total_read += bytes_read;
372 } 372 }
373 return total_read == bytes; 373 return total_read == bytes;
374 } 374 }
375 375
376 bool CreateSymbolicLink(const FilePath& target_path,
377 const FilePath& symlink_path) {
378 DCHECK(!symlink_path.empty());
379 DCHECK(!target_path.empty());
380 return ::symlink(target_path.value().c_str(),
381 symlink_path.value().c_str()) != -1;
382 }
383
384 bool ReadSymbolicLink(const FilePath& symlink_path,
385 FilePath* target_path) {
386 DCHECK(!symlink_path.empty());
387 DCHECK(target_path);
388 char buf[PATH_MAX];
389 ssize_t count = ::readlink(symlink_path.value().c_str(), buf, arraysize(buf));
390
391 if (count <= 0)
392 return false;
393
394 *target_path = FilePath(FilePath::StringType(buf, count));
395
396 return true;
397 }
398
376 // Creates and opens a temporary file in |directory|, returning the 399 // Creates and opens a temporary file in |directory|, returning the
377 // file descriptor. |path| is set to the temporary file path. 400 // file descriptor. |path| is set to the temporary file path.
378 // This function does NOT unlink() the file. 401 // This function does NOT unlink() the file.
379 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) { 402 int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
380 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp(). 403 base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp().
381 *path = directory.Append(kTempFileName); 404 *path = directory.Append(kTempFileName);
382 const std::string& tmpdir_string = path->value(); 405 const std::string& tmpdir_string = path->value();
383 // this should be OK since mkstemp just replaces characters in place 406 // this should be OK since mkstemp just replaces characters in place
384 char* buffer = const_cast<char*>(tmpdir_string.c_str()); 407 char* buffer = const_cast<char*>(tmpdir_string.c_str());
385 408
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 if (HANDLE_EINTR(close(infile)) < 0) 880 if (HANDLE_EINTR(close(infile)) < 0)
858 result = false; 881 result = false;
859 if (HANDLE_EINTR(close(outfile)) < 0) 882 if (HANDLE_EINTR(close(outfile)) < 0)
860 result = false; 883 result = false;
861 884
862 return result; 885 return result;
863 } 886 }
864 #endif // defined(OS_MACOSX) 887 #endif // defined(OS_MACOSX)
865 888
866 } // namespace file_util 889 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698