| Index: base/files/file_util_posix.cc
|
| diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc
|
| index 0bf41a52351a2e14d643a575ac8328dd478aa21a..dad8eddb170a8731639f1530874a651d770f3b84 100644
|
| --- a/base/files/file_util_posix.cc
|
| +++ b/base/files/file_util_posix.cc
|
| @@ -845,55 +845,33 @@ bool GetShmemTempDir(bool executable, FilePath* path) {
|
| }
|
| #endif // !defined(OS_ANDROID)
|
|
|
| -// -----------------------------------------------------------------------------
|
| -
|
| -namespace internal {
|
| -
|
| -bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) {
|
| - ThreadRestrictions::AssertIOAllowed();
|
| - // Windows compatibility: if to_path exists, from_path and to_path
|
| - // must be the same type, either both files, or both directories.
|
| - stat_wrapper_t to_file_info;
|
| - if (CallStat(to_path.value().c_str(), &to_file_info) == 0) {
|
| - stat_wrapper_t from_file_info;
|
| - if (CallStat(from_path.value().c_str(), &from_file_info) == 0) {
|
| - if (S_ISDIR(to_file_info.st_mode) != S_ISDIR(from_file_info.st_mode))
|
| - return false;
|
| - } else {
|
| - return false;
|
| - }
|
| - }
|
| -
|
| - if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0)
|
| - return true;
|
| -
|
| - if (!CopyDirectory(from_path, to_path, true))
|
| - return false;
|
| -
|
| - DeleteFile(from_path, true);
|
| - return true;
|
| -}
|
| -
|
| #if !defined(OS_MACOSX)
|
| // Mac has its own implementation, this is for all other Posix systems.
|
| -bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) {
|
| +bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| - int infile = HANDLE_EINTR(open(from_path.value().c_str(), O_RDONLY));
|
| - if (infile < 0)
|
| + File infile;
|
| +#if defined(OS_ANDROID)
|
| + if (from_path.IsContentUri()) {
|
| + infile = OpenContentUriForRead(from_path);
|
| + } else {
|
| + infile = File(from_path, File::FLAG_OPEN | File::FLAG_READ);
|
| + }
|
| +#else
|
| + infile = File(from_path, File::FLAG_OPEN | File::FLAG_READ);
|
| +#endif
|
| + if (!infile.IsValid())
|
| return false;
|
|
|
| - int outfile = HANDLE_EINTR(creat(to_path.value().c_str(), 0666));
|
| - if (outfile < 0) {
|
| - close(infile);
|
| + File outfile(to_path, File::FLAG_WRITE | File::FLAG_CREATE_ALWAYS);
|
| + if (!outfile.IsValid())
|
| return false;
|
| - }
|
|
|
| const size_t kBufferSize = 32768;
|
| std::vector<char> buffer(kBufferSize);
|
| bool result = true;
|
|
|
| while (result) {
|
| - ssize_t bytes_read = HANDLE_EINTR(read(infile, &buffer[0], buffer.size()));
|
| + ssize_t bytes_read = infile.ReadAtCurrentPos(&buffer[0], buffer.size());
|
| if (bytes_read < 0) {
|
| result = false;
|
| break;
|
| @@ -903,10 +881,8 @@ bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) {
|
| // Allow for partial writes
|
| ssize_t bytes_written_per_read = 0;
|
| do {
|
| - ssize_t bytes_written_partial = HANDLE_EINTR(write(
|
| - outfile,
|
| - &buffer[bytes_written_per_read],
|
| - bytes_read - bytes_written_per_read));
|
| + ssize_t bytes_written_partial = outfile.WriteAtCurrentPos(
|
| + &buffer[bytes_written_per_read], bytes_read - bytes_written_per_read);
|
| if (bytes_written_partial < 0) {
|
| result = false;
|
| break;
|
| @@ -915,15 +891,39 @@ bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) {
|
| } while (bytes_written_per_read < bytes_read);
|
| }
|
|
|
| - if (IGNORE_EINTR(close(infile)) < 0)
|
| - result = false;
|
| - if (IGNORE_EINTR(close(outfile)) < 0)
|
| - result = false;
|
| -
|
| return result;
|
| }
|
| #endif // !defined(OS_MACOSX)
|
|
|
| +// -----------------------------------------------------------------------------
|
| +
|
| +namespace internal {
|
| +
|
| +bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) {
|
| + ThreadRestrictions::AssertIOAllowed();
|
| + // Windows compatibility: if to_path exists, from_path and to_path
|
| + // must be the same type, either both files, or both directories.
|
| + stat_wrapper_t to_file_info;
|
| + if (CallStat(to_path.value().c_str(), &to_file_info) == 0) {
|
| + stat_wrapper_t from_file_info;
|
| + if (CallStat(from_path.value().c_str(), &from_file_info) == 0) {
|
| + if (S_ISDIR(to_file_info.st_mode) != S_ISDIR(from_file_info.st_mode))
|
| + return false;
|
| + } else {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0)
|
| + return true;
|
| +
|
| + if (!CopyDirectory(from_path, to_path, true))
|
| + return false;
|
| +
|
| + DeleteFile(from_path, true);
|
| + return true;
|
| +}
|
| +
|
| } // namespace internal
|
|
|
| #endif // !defined(OS_NACL_NONSFI)
|
|
|