summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/gtk/FileSystemGtk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/gtk/FileSystemGtk.cpp')
-rw-r--r--WebCore/platform/gtk/FileSystemGtk.cpp128
1 files changed, 120 insertions, 8 deletions
diff --git a/WebCore/platform/gtk/FileSystemGtk.cpp b/WebCore/platform/gtk/FileSystemGtk.cpp
index 904fe9f..965cea9 100644
--- a/WebCore/platform/gtk/FileSystemGtk.cpp
+++ b/WebCore/platform/gtk/FileSystemGtk.cpp
@@ -22,6 +22,7 @@
#include "config.h"
#include "FileSystem.h"
+#include "guriescape.h"
#include "NotImplemented.h"
#include "PlatformString.h"
#include "CString.h"
@@ -30,12 +31,61 @@
#include <glib/gstdio.h>
#include <glib/gutils.h>
+#include <unistd.h>
+
namespace WebCore {
+/* On linux file names are just raw bytes, so also strings that cannot be encoded in any way
+ * are valid file names. This mean that we cannot just store a file name as-is in a String
+ * but we have to escape it.
+ * On Windows the GLib file name encoding is always UTF-8 so we can optimize this case. */
+String filenameToString(const char* filename)
+{
+ if (!filename)
+ return String();
+
+#if PLATFORM(WIN_OS)
+ return String::fromUTF8(filename);
+#else
+ gchar* escapedString = g_uri_escape_string(filename, "/:", false);
+ String string(escapedString);
+ g_free(escapedString);
+ return string;
+#endif
+}
+
+char* filenameFromString(const String& string)
+{
+#if PLATFORM(WIN_OS)
+ return g_strdup(string.utf8().data());
+#else
+ return g_uri_unescape_string(string.utf8().data(), 0);
+#endif
+}
+
+// Converts a string to something suitable to be displayed to the user.
+String filenameForDisplay(const String& string)
+{
+#if PLATFORM(WIN_OS)
+ return string;
+#else
+ gchar* filename = filenameFromString(string);
+ gchar* display = g_filename_to_utf8(filename, 0, 0, 0, 0);
+ g_free(filename);
+ if (!display)
+ return string;
+
+ String displayString = String::fromUTF8(display);
+ g_free(display);
+
+ return displayString;
+#endif
+}
+
bool fileExists(const String& path)
{
bool result = false;
- gchar* filename = g_filename_from_utf8(path.utf8().data(), -1, 0, 0, 0);
+ gchar* filename = filenameFromString(path);
if (filename) {
result = g_file_test(filename, G_FILE_TEST_EXISTS);
@@ -48,7 +98,7 @@ bool fileExists(const String& path)
bool deleteFile(const String& path)
{
bool result = false;
- gchar* filename = g_filename_from_utf8(path.utf8().data(), -1, 0, 0, 0);
+ gchar* filename = filenameFromString(path);
if (filename) {
result = g_remove(filename) == 0;
@@ -61,7 +111,7 @@ bool deleteFile(const String& path)
bool deleteEmptyDirectory(const String& path)
{
bool result = false;
- gchar* filename = g_filename_from_utf8(path.utf8().data(), -1, 0, 0, 0);
+ gchar* filename = filenameFromString(path);
if (filename) {
result = g_rmdir(filename) == 0;
@@ -73,7 +123,7 @@ bool deleteEmptyDirectory(const String& path)
bool getFileSize(const String& path, long long& resultSize)
{
- gchar* filename = g_filename_from_utf8(path.utf8().data(), -1, 0, 0, 0);
+ gchar* filename = filenameFromString(path);
if (!filename)
return false;
@@ -87,10 +137,21 @@ bool getFileSize(const String& path, long long& resultSize)
return true;
}
-bool getFileModificationTime(const String&, time_t&)
+bool getFileModificationTime(const String& path, time_t& modifiedTime)
{
- notImplemented();
- return false;
+ gchar* filename = filenameFromString(path);
+ if (!filename)
+ return false;
+
+ struct stat statResult;
+ gint result = g_stat(filename, &statResult);
+ g_free(filename);
+ if (result != 0)
+ return false;
+
+ modifiedTime = statResult.st_mtime;
+ return true;
+
}
String pathByAppendingComponent(const String& path, const String& component)
@@ -103,7 +164,7 @@ String pathByAppendingComponent(const String& path, const String& component)
bool makeAllDirectories(const String& path)
{
- gchar* filename = g_filename_from_utf8(path.utf8().data(), -1, 0, 0, 0);
+ gchar* filename = filenameFromString(path);
if (!filename)
return false;
@@ -113,6 +174,52 @@ bool makeAllDirectories(const String& path)
return result == 0;
}
+String homeDirectoryPath()
+{
+ return filenameToString(g_get_home_dir());
+}
+
+String pathGetFileName(const String& pathName)
+{
+ char* tmpFilename = filenameFromString(pathName);
+ char* baseName = g_path_get_basename(tmpFilename);
+ String fileName = String::fromUTF8(baseName);
+ g_free(baseName);
+ g_free(tmpFilename);
+
+ return fileName;
+}
+
+String directoryName(const String& path)
+{
+ notImplemented();
+ return String();
+}
+
+Vector<String> listDirectory(const String& path, const String& filter)
+{
+ Vector<String> entries;
+
+ gchar* filename = filenameFromString(path);
+ GDir* dir = g_dir_open(filename, 0, 0);
+ if (!dir)
+ return entries;
+
+ GPatternSpec *pspec = g_pattern_spec_new((filter.utf8()).data());
+ while (const char* name = g_dir_read_name(dir)) {
+ if (!g_pattern_match_string(pspec, name))
+ continue;
+
+ gchar* entry = g_build_filename(filename, name, NULL);
+ entries.append(filenameToString(entry));
+ g_free(entry);
+ }
+ g_dir_close(dir);
+ g_free(filename);
+
+ return entries;
+}
+
CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle)
{
gchar* filename = g_strdup_printf("%sXXXXXX", prefix);
@@ -152,4 +259,9 @@ int writeToFile(PlatformFileHandle handle, const char* data, int length)
return totalBytesWritten;
}
+
+bool unloadModule(PlatformModule module)
+{
+ return g_module_close(module);
+}
}