[Title] Make FileWriter writes from current position and fire error type progress event when written
bytes are less than expectation
[Issue#] N/A
[Problem]
[Cause]
[Solution]
- OpenFile without O_TRUNC option for avoiding data crash of file with lseek and write
- Seek to the position before start to write
- Make SECURITY_ERR when write operation is completed but bytes of written is not equal to the expectation
Change-Id: I1806c2df80f7745b7f5a7efd28dee78455d7f54d
enum FileOpenMode {
OpenForRead = 0,
OpenForWrite
+#if ENABLE(TIZEN_FILE_SYSTEM)
+ , OpenForWriteOnly
+#endif
};
enum FileSeekOrigin {
{
int bytesWritten;
PlatformFileHandle handle;
- handle = openFile(path, OpenForWrite);
+ handle = openFile(path, OpenForWriteOnly);
if (!isHandleValid(handle)) {
helperClient->didFail(FileError::NOT_FOUND_ERR);
return;
}
+ seekFile(handle, position, SeekFromBeginning);
RefPtr<BlobStorageData> blobStorage = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(data->url());
if (blobStorage) {
for (size_t i = 0; i < blobStorage->items().size(); i++) {
bytesWritten = 0;
bytesWritten = writeToFile(handle, blobItem.data->data(), blobItem.data->length());
- if (bytesWritten < 0)
+ if (bytesWritten != blobItem.data->length())
helperClient->didFail(FileError::SECURITY_ERR);
else
helperClient->didWrite(bytesWritten, (i + 1 == blobStorage->items().size()) ? true : false);
#if ENABLE(TIZEN_FILE_SYSTEM)
#include "FileMetadata.h"
#include <dirent.h>
+#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
return !link(fsRepSource.data(), fsRepDestination.data());
}
+PlatformFileHandle openFile(const String& path, FileOpenMode mode)
+{
+ CString fsRep = fileSystemRepresentation(path);
+
+ if (fsRep.isNull())
+ return invalidPlatformFileHandle;
+
+ int platformFlag = 0;
+ if (mode == OpenForRead)
+ platformFlag |= O_RDONLY;
+ else if (mode == OpenForWrite)
+ platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC);
+ else if (mode == OpenForWriteOnly)
+ platformFlag |= (O_WRONLY);
+ return open(fsRep.data(), platformFlag, 0666);
+}
+
bool renameFile(const String& sourcePath, const String& destinationPath)
{
CString fsRepSource = fileSystemRepresentation(sourcePath);
return !unlink(fsRep.data());
}
+#if !ENABLE(TIZEN_FILE_SYSTEM)
PlatformFileHandle openFile(const String& path, FileOpenMode mode)
{
CString fsRep = fileSystemRepresentation(path);
platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC);
return open(fsRep.data(), platformFlag, 0666);
}
+#endif
void closeFile(PlatformFileHandle& handle)
{