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

Unified Diff: base/files/file_util_posix.cc

Issue 603683005: base::CopyFile can copy *from* Android's content scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified CopyFile test to assert inability to copy to parent dir. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/files/file_util_unittest.cc » ('j') | base/files/file_util_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util_posix.cc
diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc
index b8c0eeb94c0088d07aa41f7e4e7bf593ea72094d..0e9fbb94a409dc86c39004bb79d65f80a4063af5 100644
--- a/base/files/file_util_posix.cc
+++ b/base/files/file_util_posix.cc
@@ -880,22 +880,29 @@ bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) {
// Mac has its own implementation, this is for all other Posix systems.
bool CopyFileUnsafe(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;
@@ -905,10 +912,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;
@@ -917,11 +922,6 @@ 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)
« no previous file with comments | « no previous file | base/files/file_util_unittest.cc » ('j') | base/files/file_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698