#include "webkit/browser/fileapi/native_file_util.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/memory/scoped_ptr.h"
-#include "net/base/file_stream.h"
#include "webkit/browser/fileapi/file_system_operation_context.h"
#include "webkit/browser/fileapi/file_system_url.h"
// Copies a file |from| to |to|, and ensure the written content is synced to
// the disk. This is essentially base::CopyFile followed by fsync().
bool CopyFileAndSync(const base::FilePath& from, const base::FilePath& to) {
- net::FileStream infile(NULL);
- if (infile.OpenSync(from,
- base::PLATFORM_FILE_OPEN | base:: PLATFORM_FILE_READ) < 0) {
+ base::File infile(from, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ if (!infile.IsValid()) {
return false;
}
- net::FileStream outfile(NULL);
- if (outfile.OpenSync(to,
- base::PLATFORM_FILE_CREATE_ALWAYS | base:: PLATFORM_FILE_WRITE) < 0) {
+ base::File outfile(to,
+ base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+ if (!outfile.IsValid()) {
return false;
}
std::vector<char> buffer(kBufferSize);
for (;;) {
- int bytes_read = infile.ReadSync(&buffer[0], kBufferSize);
+ int bytes_read = infile.ReadAtCurrentPos(&buffer[0], kBufferSize);
if (bytes_read < 0)
return false;
if (bytes_read == 0)
break;
for (int bytes_written = 0; bytes_written < bytes_read; ) {
- int bytes_written_partial = outfile.WriteSync(&buffer[bytes_written],
- bytes_read - bytes_written);
+ int bytes_written_partial = outfile.WriteAtCurrentPos(
+ &buffer[bytes_written], bytes_read - bytes_written);
if (bytes_written_partial < 0)
return false;
bytes_written += bytes_written_partial;
}
}
- return outfile.FlushSync() >= 0;
+ return outfile.Flush();
}
} // namespace
return MOVE;
}
-base::File::Error NativeFileUtil::CreateOrOpen(
- const base::FilePath& path, int file_flags,
- PlatformFile* file_handle, bool* created) {
+base::File NativeFileUtil::CreateOrOpen(const base::FilePath& path,
+ int file_flags) {
if (!base::DirectoryExists(path.DirName())) {
// If its parent does not exist, should return NOT_FOUND error.
- return base::File::FILE_ERROR_NOT_FOUND;
+ return base::File(base::File::FILE_ERROR_NOT_FOUND);
}
- if (base::DirectoryExists(path))
- return base::File::FILE_ERROR_NOT_A_FILE;
- // TODO(rvargas): convert this code to use base::File.
- base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
- *file_handle = base::CreatePlatformFile(path, file_flags,
- created, &error_code);
- return static_cast<base::File::Error>(error_code);
-}
+ // TODO(rvargas): Check |file_flags| instead. See bug 356358.
+ if (base::DirectoryExists(path))
+ return base::File(base::File::FILE_ERROR_NOT_A_FILE);
-base::File::Error NativeFileUtil::Close(PlatformFile file_handle) {
- if (!base::ClosePlatformFile(file_handle))
- return base::File::FILE_ERROR_FAILED;
- return base::File::FILE_OK;
+ return base::File(path, file_flags);
}
base::File::Error NativeFileUtil::EnsureFileExists(