[GTK][WPE] Enable FILE_LOCK and implement lockFile and unlockFile
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jul 2017 06:59:15 +0000 (06:59 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jul 2017 06:59:15 +0000 (06:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174357

Reviewed by Michael Catanzaro.

.:

* Source/cmake/OptionsGTK.cmake: Use gio-unix unconditionally.

Source/WebCore:

Implement lockFile and unlockFile using flock().

* PlatformWPE.cmake:
* platform/glib/FileSystemGlib.cpp:
(WebCore::lockFile):
(WebCore::unlockFile):

Source/WTF:

* wtf/Platform.h: Enable FILE_LOCK in GTK and WPE ports.

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

ChangeLog
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/PlatformWPE.cmake
Source/WebCore/platform/glib/FileSystemGlib.cpp
Source/cmake/OptionsGTK.cmake

index 0430c2cdd4ab4fb30b5bb15f28af1fe6482ea380..244d90713db6b2f80d66be8c202d0d944f1c12f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-07-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WPE] Enable FILE_LOCK and implement lockFile and unlockFile
+        https://bugs.webkit.org/show_bug.cgi?id=174357
+
+        Reviewed by Michael Catanzaro.
+
+        * Source/cmake/OptionsGTK.cmake: Use gio-unix unconditionally.
+
 2017-07-11  Dean Jackson  <dino@apple.com>
 
         Remove NAVIGATOR_HWCONCURRENCY
index d97faac483f6fe972283173748f71038f4721319..537558ca6fce02fe4a46e0bc8a8848277bbbd938 100644 (file)
@@ -1,3 +1,12 @@
+2017-07-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WPE] Enable FILE_LOCK and implement lockFile and unlockFile
+        https://bugs.webkit.org/show_bug.cgi?id=174357
+
+        Reviewed by Michael Catanzaro.
+
+        * wtf/Platform.h: Enable FILE_LOCK in GTK and WPE ports.
+
 2017-07-11  Dean Jackson  <dino@apple.com>
 
         Remove NAVIGATOR_HWCONCURRENCY
index c06d280ed831666028e0e62728f1041a613a4a02..3d02b9c8553b5b5261a8aedce62e815373ffb41f 100644 (file)
 #define USE_HARFBUZZ 1
 #define USE_SOUP 1
 #define USE_WEBP 1
+#define USE_FILE_LOCK 1
 #endif
 
 #if PLATFORM(GTK)
index 5c362bc34e8987bcffa83e417458a789915bcf11..44f2be0cab6d23043fc43c0398d84baa7d586c59 100644 (file)
@@ -1,3 +1,17 @@
+2017-07-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WPE] Enable FILE_LOCK and implement lockFile and unlockFile
+        https://bugs.webkit.org/show_bug.cgi?id=174357
+
+        Reviewed by Michael Catanzaro.
+
+        Implement lockFile and unlockFile using flock().
+
+        * PlatformWPE.cmake:
+        * platform/glib/FileSystemGlib.cpp:
+        (WebCore::lockFile):
+        (WebCore::unlockFile):
+
 2017-07-11  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Use FastAllocator in STL containers
index 9c8a55c08c5034bdb2221ad4e217742dbad5e1f4..8fde49a96cc202ee99512a28250aa1feee3228bc 100644 (file)
@@ -180,6 +180,7 @@ list(APPEND WebCore_LIBRARIES
 list(APPEND WebCore_INCLUDE_DIRECTORIES
     ${CAIRO_INCLUDE_DIRS}
     ${EGL_INCLUDE_DIRS}
+    ${GIO_UNIX_INCLUDE_DIRS}
     ${GLIB_INCLUDE_DIRS}
     ${GNUTLS_INCLUDE_DIRS}
     ${ICU_INCLUDE_DIRS}
index 94f24d5b097476e8c6911e747632a32388cb21de..a6e2eeef705f7f6940320f6348bf83d035d03d1b 100644 (file)
 
 #include "FileMetadata.h"
 #include "NotImplemented.h"
+#include <gio/gfiledescriptorbased.h>
 #include <gio/gio.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <sys/file.h>
 #include <wtf/UUID.h>
 #include <wtf/glib/GLibUtilities.h>
 #include <wtf/glib/GRefPtr.h>
@@ -417,4 +419,23 @@ std::optional<int32_t> getFileDeviceId(const CString& fsFile)
     return g_file_info_get_attribute_uint32(fileInfo.get(), G_FILE_ATTRIBUTE_UNIX_DEVICE);
 }
 
+#if USE(FILE_LOCK)
+bool lockFile(PlatformFileHandle handle, FileLockMode lockMode)
+{
+    COMPILE_ASSERT(LOCK_SH == LockShared, LockSharedEncodingIsAsExpected);
+    COMPILE_ASSERT(LOCK_EX == LockExclusive, LockExclusiveEncodingIsAsExpected);
+    COMPILE_ASSERT(LOCK_NB == LockNonBlocking, LockNonBlockingEncodingIsAsExpected);
+    auto* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(handle));
+    int result = flock(g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream)), lockMode);
+    return result != -1;
+}
+
+bool unlockFile(PlatformFileHandle handle)
+{
+    auto* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(handle));
+    int result = flock(g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream)), LOCK_UN);
+    return result != -1;
+}
+#endif // USE(FILE_LOCK)
+
 }
index 637ac659cf169eb734195efc5804ce6d2d13090f..606a84317b474bb8ec8e17f446b1ac123e5c722b 100644 (file)
@@ -199,10 +199,7 @@ set(GDK_INCLUDE_DIRS ${GDK3_INCLUDE_DIRS})
 SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_GESTURES ${GTK3_SUPPORTS_GESTURES})
 SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_UNIX_PRINTING ${GTK_UNIX_PRINT_FOUND})
 
-set(glib_components gio gobject gthread gmodule)
-if (ENABLE_GAMEPAD_DEPRECATED OR ENABLE_GEOLOCATION)
-    list(APPEND glib_components gio-unix)
-endif ()
+set(glib_components gio gio-unix gobject gthread gmodule)
 find_package(GLIB 2.36 REQUIRED COMPONENTS ${glib_components})
 
 if (ENABLE_XSLT)