[gjs] context: Use g_file_new_for_commandline_arg in gjs_context_eval_file
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] context: Use g_file_new_for_commandline_arg in gjs_context_eval_file
- Date: Tue, 14 Jan 2014 23:49:01 +0000 (UTC)
commit d68919fa0e7b9846e0638b648e297b04e65ed281
Author: Sam Spilsbury <smspillaz gmail com>
Date: Wed Jan 8 13:52:11 2014 -0200
context: Use g_file_new_for_commandline_arg in gjs_context_eval_file
g_file_get_contents uses open() directly, but we really want to create
a file using GVFS so that we can evaluate files which are actually
resource URIs.
https://bugzilla.gnome.org/show_bug.cgi?id=721246
gjs/context.cpp | 28 +++++++++++++++++++++-------
1 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index cb9cf9a..7fd11dd 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -23,6 +23,8 @@
#include <config.h>
+#include <gio/gio.h>
+
#include "context.h"
#include "importer.h"
#include "jsapi-util.h"
@@ -873,19 +875,31 @@ gjs_context_eval_file(GjsContext *js_context,
int *exit_status_p,
GError **error)
{
- char *script;
- gsize script_len;
+ char *script = NULL;
+ gsize script_len;
+ gboolean ret = TRUE;
- if (!g_file_get_contents(filename, &script, &script_len, error))
- return FALSE;
+ GFile *file = g_file_new_for_commandline_arg(filename);
+
+ if (!g_file_query_exists(file, NULL)) {
+ ret = FALSE;
+ goto out;
+ }
+
+ if (!g_file_load_contents(file, NULL, &script, &script_len, NULL, error)) {
+ ret = FALSE;
+ goto out;
+ }
if (!gjs_context_eval(js_context, script, script_len, filename, exit_status_p, error)) {
- g_free(script);
- return FALSE;
+ ret = FALSE;
+ goto out;
}
+out:
g_free(script);
- return TRUE;
+ g_object_unref(file);
+ return ret;
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]