Need to use _wstat instead of _stat to stat files on windows
authoroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Sep 2007 00:10:45 +0000 (00:10 +0000)
committeroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Sep 2007 00:10:45 +0000 (00:10 +0000)
_stat doesn't handle multibyte character sequences, unless (afaict)
the current codepage supports them, and then it uses the current
codepage.  In order to correctly handle multibyte characters in a
file path we have to use _wstat.

In deference to the fact that the CF implementation may be used on
platforms other than windows i've added fileSize to the FileSystem
helper functions, and added a windows impl.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25577 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/platform/FileSystem.h
WebCore/platform/gdk/TemporaryLinkStubs.cpp
WebCore/platform/mac/FileSystemMac.mm
WebCore/platform/network/cf/FormDataStreamCFNet.cpp
WebCore/platform/qt/TemporaryLinkStubs.cpp
WebCore/platform/win/FileSystemWin.cpp [new file with mode: 0644]

index b438c0caefbd71dc7fdb41eb25d3d003b74d9927..e23e83375e10a31e358f3430d38b621b0c484273 100644 (file)
@@ -1,3 +1,27 @@
+2007-09-14  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Sam and Geoff.
+
+        <rdar://problem/5333272> Cannot upload files when path contains 
+        non-ascii/multibyte characters
+
+        We can't use _stat to determine file size on Windows as it may not 
+        correctly handle multibyte characters, so we have to use _wstat.
+        
+        In deference to the fact that we may one day use the FormDataStreamCFNet.cpp
+        on Mac i've wrapped the call to _wstat with a generic fileSize
+        method in FileSystem.h
+
+        * WebCore.vcproj/WebCore.vcproj:
+        * platform/FileSystem.h:
+        * platform/network/cf/FormDataStreamCFNet.cpp:
+        * platform/win/FileSystemWin.cpp: Added.
+        (WebCore::setHTTPBody):
+        * platform/gdk/TemporaryLinkStubs.cpp:
+        * platform/mac/FileSystemMac.mm:
+        (WebCore::fileSize):
+        * platform/qt/TemporaryLinkStubs.cpp:
+
 2007-09-14  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Sam.
index 67838e1a27243d5410ac16c6006662dcc5dc24f0..0bbc430a12a2724ff3bc16dc495df46ec8e5bf2b 100644 (file)
                                RelativePath="..\platform\FileChooser.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\platform\FileSystem.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\platform\FloatConversion.h"
                                >
                                        RelativePath="..\platform\win\FileChooserWin.cpp"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\platform\win\FileSystemWin.cpp"
+                                       >
+                               </File>
                                <File
                                        RelativePath="..\platform\win\FontCacheWin.cpp"
                                        >
index 8477486bea93282dcfe7ba5cdb2e4b547a2efe0b..84896082b2659ad548d9f702e0f401a7c8be5de0 100644 (file)
@@ -35,6 +35,7 @@ class String;
 
 bool fileExists(const String&);
 bool deleteFile(const String&);
+bool fileSize(const String&, long long& result);
 
 } // namespace WebCore
 
index cbdb236ab318302f706bf343b5d780d59b7712fa..2ec0c34c75be51d360e6be4946ef899feb6a2228 100644 (file)
@@ -182,6 +182,7 @@ String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String &ch
 float userIdleTime() { notImplemented(); return 0.0; }
 bool fileExists(const String& path) { notImplemented(); return false; }
 bool deleteFile(const String& path) { notImplemented(); return false; }
+bool fileSize(const String& path, long long& result) { notImplemented(); return false; }
 void callOnMainThread(void (*)()) { notImplemented(); }
 }
 
index 17010eecef0eac61619f4073c5c98dc5c79746c6..0ec4cb78ce34cbf32e561e8b5c52752abe01fefd 100644 (file)
@@ -28,6 +28,7 @@
 #import "config.h"
 #import "FileSystem.h"
 
+#import "NotImplemented.h"
 #import "PlatformString.h"
 
 namespace WebCore {
@@ -56,4 +57,10 @@ bool deleteFile(const String& path)
     return !unlink(fsRep);
 }
 
+bool fileSize(const String& path, long long& result)
+{
+    notImplemented();
+    return false;
+}
+
 } //namespace WebCore
index f834e7dba96fe373c13f7f8aa8d4a2f29bff24b7..2bee82dadbf463986747d61db4cd616c589d760c 100644 (file)
 #include "FormDataStreamCFNet.h"
 
 #include "CString.h"
+#include "FileSystem.h"
 #include "FormData.h"
 #include <CFNetwork/CFURLRequestPriv.h>
 #include <CoreFoundation/CFStreamAbstract.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
@@ -340,10 +340,9 @@ void setHTTPBody(CFMutableURLRequestRef request, PassRefPtr<FormData> formData)
         if (element.m_type == FormDataElement::data)
             length += element.m_data.size();
         else {
-            struct _stat64i32 sb;
-            int statResult = _stat(element.m_filename.utf8().data(), &sb);
-            if (statResult == 0 && (sb.st_mode & S_IFMT) == S_IFREG)
-                length += sb.st_size;
+            long long size;
+            if (fileSize(element.m_filename, size))
+                length += size;
             else
                 haveLength = false;
         }
index c2b00950b1e27643e05ba90a31648a5242c45889..a9ebc6745457e238969af1543cd39a5d15534bb8 100644 (file)
@@ -83,6 +83,7 @@ Vector<String> supportedKeySizes() { notImplemented(); return Vector<String>();
 String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String &challengeString, const KURL &url) { return String(); }
 
 float userIdleTime() { notImplemented(); return 0.0; }
+bool fileSize(const String& path, long long& result) { notImplemented(); return false; }
 
 }
 
diff --git a/WebCore/platform/win/FileSystemWin.cpp b/WebCore/platform/win/FileSystemWin.cpp
new file mode 100644 (file)
index 0000000..b983705
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "FileSystem.h"
+#include "PlatformString.h"
+
+#include <sys/stat.h>
+
+namespace WebCore {
+
+bool fileSize(const String& inFilename, long long& result)
+{
+    struct _stat64i32 sb;
+    String filename = inFilename;
+    int statResult = _wstat(filename.charactersWithNullTermination(), &sb);
+    if (statResult != 0 || (sb.st_mode & S_IFMT) != S_IFREG)
+        return false;
+    result = sb.st_size;
+    return true;
+}
+
+}