Make FileWriter writes from current position and change failure condition
authorJihye Kang <jye.kang@samsung.com>
Tue, 9 Apr 2013 15:27:03 +0000 (00:27 +0900)
committerJihye Kang <jye.kang@samsung.com>
Wed, 10 Apr 2013 02:56:28 +0000 (11:56 +0900)
[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

Source/WebCore/platform/FileSystem.h
Source/WebCore/platform/efl/tizen/AsyncFileWriterTizen.cpp
Source/WebCore/platform/efl/tizen/FileSystemTizen.cpp
Source/WebCore/platform/posix/FileSystemPOSIX.cpp

index 7529d20..867f820 100644 (file)
@@ -144,6 +144,9 @@ const PlatformFileHandle invalidPlatformFileHandle = -1;
 enum FileOpenMode {
     OpenForRead = 0,
     OpenForWrite
+#if ENABLE(TIZEN_FILE_SYSTEM)
+    , OpenForWriteOnly
+#endif
 };
 
 enum FileSeekOrigin {
index 2925e1f..5797496 100644 (file)
@@ -47,7 +47,7 @@ static void writeAsync(ScriptExecutionContext* context, PassOwnPtr<AsyncFileWrit
 {
     int bytesWritten;
     PlatformFileHandle handle;
-    handle = openFile(path, OpenForWrite);
+    handle = openFile(path, OpenForWriteOnly);
 
     if (!isHandleValid(handle)) {
         helperClient->didFail(FileError::NOT_FOUND_ERR);
@@ -61,6 +61,7 @@ static void writeAsync(ScriptExecutionContext* context, PassOwnPtr<AsyncFileWrit
         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++) {
@@ -69,7 +70,7 @@ static void writeAsync(ScriptExecutionContext* context, PassOwnPtr<AsyncFileWrit
                 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);
index 731e711..1d84bb8 100644 (file)
@@ -32,6 +32,7 @@
 #if ENABLE(TIZEN_FILE_SYSTEM)
 #include "FileMetadata.h"
 #include <dirent.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -105,6 +106,23 @@ bool linkFile(const String& sourcePath, const String& destinationPath)
     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);
index 08d711f..7b9df88 100644 (file)
@@ -76,6 +76,7 @@ bool deleteFile(const String& path)
     return !unlink(fsRep.data());
 }
 
+#if !ENABLE(TIZEN_FILE_SYSTEM)
 PlatformFileHandle openFile(const String& path, FileOpenMode mode)
 {
     CString fsRep = fileSystemRepresentation(path);
@@ -90,6 +91,7 @@ PlatformFileHandle openFile(const String& path, FileOpenMode mode)
         platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC);
     return open(fsRep.data(), platformFlag, 0666);
 }
+#endif
 
 void closeFile(PlatformFileHandle& handle)
 {