|
|
f47161 |
From 489166afdd82af3ec4897c8369a89bbaeffea2d9 Mon Sep 17 00:00:00 2001
|
|
|
b31790 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
b31790 |
Date: Fri, 20 Dec 2013 11:22:07 -0500
|
|
|
b31790 |
Subject: [PATCH 09/19] Revert "Allow saved-session to be a symlink"
|
|
|
b31790 |
|
|
|
b31790 |
This reverts commit b733c2ee519b65c3c4eab0d0e93056412f995f3f.
|
|
|
b31790 |
---
|
|
|
f47161 |
gnome-session/gsm-session-save.c | 33 +++++++++++++++++++++++++++-----
|
|
|
b31790 |
gnome-session/gsm-util.c | 6 ++++++
|
|
|
f47161 |
2 files changed, 34 insertions(+), 5 deletions(-)
|
|
|
b31790 |
|
|
|
b31790 |
diff --git a/gnome-session/gsm-session-save.c b/gnome-session/gsm-session-save.c
|
|
|
f47161 |
index a71a6181..04b5277c 100644
|
|
|
b31790 |
--- a/gnome-session/gsm-session-save.c
|
|
|
b31790 |
+++ b/gnome-session/gsm-session-save.c
|
|
|
f47161 |
@@ -10,61 +10,61 @@
|
|
|
b31790 |
* This program is distributed in the hope that it will be useful, but
|
|
|
b31790 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
b31790 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
b31790 |
* Lesser General Public License for more details.
|
|
|
b31790 |
*
|
|
|
b31790 |
* You should have received a copy of the GNU General Public License
|
|
|
b31790 |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
b31790 |
*/
|
|
|
b31790 |
|
|
|
b31790 |
#include <config.h>
|
|
|
b31790 |
|
|
|
b31790 |
#include <glib.h>
|
|
|
b31790 |
#include <glib/gstdio.h>
|
|
|
b31790 |
#include <gio/gio.h>
|
|
|
b31790 |
|
|
|
f47161 |
#include "gsm-app.h"
|
|
|
b31790 |
#include "gsm-util.h"
|
|
|
b31790 |
#include "gsm-autostart-app.h"
|
|
|
b31790 |
#include "gsm-client.h"
|
|
|
b31790 |
|
|
|
b31790 |
#include "gsm-session-save.h"
|
|
|
b31790 |
|
|
|
b31790 |
#define GSM_MANAGER_SCHEMA "org.gnome.SessionManager"
|
|
|
b31790 |
#define KEY_AUTOSAVE_ONE_SHOT "auto-save-session-one-shot"
|
|
|
b31790 |
|
|
|
b31790 |
|
|
|
b31790 |
static gboolean gsm_session_clear_saved_session (const char *directory,
|
|
|
b31790 |
GHashTable *discard_hash);
|
|
|
b31790 |
|
|
|
b31790 |
typedef struct {
|
|
|
b31790 |
- const char *dir;
|
|
|
b31790 |
+ char *dir;
|
|
|
b31790 |
GHashTable *discard_hash;
|
|
|
f47161 |
GsmStore *app_store;
|
|
|
b31790 |
GError **error;
|
|
|
b31790 |
} SessionSaveData;
|
|
|
b31790 |
|
|
|
b31790 |
static gboolean
|
|
|
f47161 |
_app_has_app_id (const char *id,
|
|
|
f47161 |
GsmApp *app,
|
|
|
f47161 |
const char *app_id_a)
|
|
|
f47161 |
{
|
|
|
f47161 |
const char *app_id_b;
|
|
|
f47161 |
|
|
|
f47161 |
app_id_b = gsm_app_peek_app_id (app);
|
|
|
f47161 |
return g_strcmp0 (app_id_a, app_id_b) == 0;
|
|
|
f47161 |
}
|
|
|
f47161 |
|
|
|
f47161 |
static gboolean
|
|
|
b31790 |
save_one_client (char *id,
|
|
|
b31790 |
GObject *object,
|
|
|
b31790 |
SessionSaveData *data)
|
|
|
b31790 |
{
|
|
|
b31790 |
GsmClient *client;
|
|
|
b31790 |
GKeyFile *keyfile;
|
|
|
f47161 |
GsmApp *app = NULL;
|
|
|
b31790 |
const char *app_id;
|
|
|
b31790 |
char *path = NULL;
|
|
|
b31790 |
char *filename = NULL;
|
|
|
b31790 |
char *contents = NULL;
|
|
|
b31790 |
gsize length = 0;
|
|
|
b31790 |
char *discard_exec;
|
|
|
f47161 |
@@ -130,91 +130,114 @@ save_one_client (char *id,
|
|
|
b31790 |
|
|
|
b31790 |
g_debug ("GsmSessionSave: saved client %s to %s", id, filename);
|
|
|
b31790 |
|
|
|
b31790 |
out:
|
|
|
b31790 |
if (keyfile != NULL) {
|
|
|
b31790 |
g_key_file_free (keyfile);
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
g_free (contents);
|
|
|
b31790 |
g_free (filename);
|
|
|
b31790 |
g_free (path);
|
|
|
b31790 |
|
|
|
b31790 |
/* in case of any error, stop saving session */
|
|
|
b31790 |
if (local_error) {
|
|
|
b31790 |
g_propagate_error (data->error, local_error);
|
|
|
b31790 |
g_error_free (local_error);
|
|
|
b31790 |
|
|
|
b31790 |
return TRUE;
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
return FALSE;
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
void
|
|
|
b31790 |
gsm_session_save (GsmStore *client_store,
|
|
|
f47161 |
GsmStore *app_store,
|
|
|
b31790 |
GError **error)
|
|
|
b31790 |
{
|
|
|
b31790 |
GSettings *settings;
|
|
|
b31790 |
const char *save_dir;
|
|
|
b31790 |
+ char *tmp_dir;
|
|
|
b31790 |
SessionSaveData data;
|
|
|
b31790 |
|
|
|
b31790 |
g_debug ("GsmSessionSave: Saving session");
|
|
|
b31790 |
|
|
|
b31790 |
/* Clear one shot key autosave in the event its set (so that it's actually
|
|
|
b31790 |
* one shot only)
|
|
|
b31790 |
*/
|
|
|
b31790 |
settings = g_settings_new (GSM_MANAGER_SCHEMA);
|
|
|
b31790 |
g_settings_set_boolean (settings, KEY_AUTOSAVE_ONE_SHOT, FALSE);
|
|
|
b31790 |
g_object_unref (settings);
|
|
|
b31790 |
|
|
|
b31790 |
save_dir = gsm_util_get_saved_session_dir ();
|
|
|
b31790 |
if (save_dir == NULL) {
|
|
|
b31790 |
g_warning ("GsmSessionSave: cannot create saved session directory");
|
|
|
b31790 |
return;
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
- data.dir = save_dir;
|
|
|
b31790 |
+ tmp_dir = gsm_util_get_empty_tmp_session_dir ();
|
|
|
b31790 |
+ if (tmp_dir == NULL) {
|
|
|
b31790 |
+ g_warning ("GsmSessionSave: cannot create new saved session directory");
|
|
|
b31790 |
+ return;
|
|
|
b31790 |
+ }
|
|
|
b31790 |
+
|
|
|
b31790 |
+ /* save the session in a temp directory, and remember the discard
|
|
|
b31790 |
+ * commands */
|
|
|
b31790 |
+ data.dir = tmp_dir;
|
|
|
b31790 |
data.discard_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
b31790 |
g_free, NULL);
|
|
|
f47161 |
data.app_store = app_store;
|
|
|
f47161 |
-
|
|
|
b31790 |
- /* remove old saved session */
|
|
|
b31790 |
- gsm_session_clear_saved_session (save_dir, data.discard_hash);
|
|
|
b31790 |
data.error = error;
|
|
|
b31790 |
|
|
|
b31790 |
gsm_store_foreach (client_store,
|
|
|
b31790 |
(GsmStoreFunc) save_one_client,
|
|
|
b31790 |
&data);
|
|
|
b31790 |
|
|
|
b31790 |
+ if (!*error) {
|
|
|
b31790 |
+ /* remove the old saved session */
|
|
|
b31790 |
+ gsm_session_clear_saved_session (save_dir, data.discard_hash);
|
|
|
b31790 |
+
|
|
|
b31790 |
+ /* rename the temp session dir */
|
|
|
b31790 |
+ if (g_file_test (save_dir, G_FILE_TEST_IS_DIR))
|
|
|
b31790 |
+ g_rmdir (save_dir);
|
|
|
b31790 |
+ g_rename (tmp_dir, save_dir);
|
|
|
b31790 |
+ } else {
|
|
|
b31790 |
+ g_warning ("GsmSessionSave: error saving session: %s", (*error)->message);
|
|
|
b31790 |
+ /* FIXME: we should create a hash table filled with the discard
|
|
|
b31790 |
+ * commands that are in desktop files from save_dir. */
|
|
|
b31790 |
+ gsm_session_clear_saved_session (tmp_dir, NULL);
|
|
|
b31790 |
+ g_rmdir (tmp_dir);
|
|
|
b31790 |
+ }
|
|
|
b31790 |
+
|
|
|
b31790 |
g_hash_table_destroy (data.discard_hash);
|
|
|
b31790 |
+ g_free (tmp_dir);
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
static gboolean
|
|
|
b31790 |
gsm_session_clear_one_client (const char *filename,
|
|
|
b31790 |
GHashTable *discard_hash)
|
|
|
b31790 |
{
|
|
|
b31790 |
gboolean result = TRUE;
|
|
|
b31790 |
GKeyFile *key_file;
|
|
|
b31790 |
char *discard_exec = NULL;
|
|
|
b31790 |
char **envp;
|
|
|
b31790 |
|
|
|
b31790 |
g_debug ("GsmSessionSave: removing '%s' from saved session", filename);
|
|
|
b31790 |
|
|
|
b31790 |
envp = (char **) gsm_util_listenv ();
|
|
|
b31790 |
key_file = g_key_file_new ();
|
|
|
b31790 |
if (g_key_file_load_from_file (key_file, filename,
|
|
|
b31790 |
G_KEY_FILE_NONE, NULL)) {
|
|
|
b31790 |
char **argv;
|
|
|
b31790 |
int argc;
|
|
|
b31790 |
|
|
|
b31790 |
discard_exec = g_key_file_get_string (key_file,
|
|
|
b31790 |
G_KEY_FILE_DESKTOP_GROUP,
|
|
|
b31790 |
GSM_AUTOSTART_APP_DISCARD_KEY,
|
|
|
b31790 |
NULL);
|
|
|
b31790 |
if (!discard_exec)
|
|
|
b31790 |
goto out;
|
|
|
b31790 |
|
|
|
b31790 |
if (discard_hash && g_hash_table_lookup (discard_hash, discard_exec))
|
|
|
b31790 |
goto out;
|
|
|
b31790 |
|
|
|
b31790 |
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
|
|
|
f47161 |
index acb446a3..b086568c 100644
|
|
|
b31790 |
--- a/gnome-session/gsm-util.c
|
|
|
b31790 |
+++ b/gnome-session/gsm-util.c
|
|
|
b31790 |
@@ -71,63 +71,69 @@ gsm_util_find_desktop_file_for_app_name (const char *name,
|
|
|
b31790 |
g_debug ("GsmUtil: found in XDG dirs: '%s'", app_path);
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
/* look for gnome vendor prefix */
|
|
|
b31790 |
if (app_path == NULL) {
|
|
|
b31790 |
g_free (desktop_file);
|
|
|
b31790 |
desktop_file = g_strdup_printf ("gnome-%s.desktop", name);
|
|
|
b31790 |
|
|
|
b31790 |
g_key_file_load_from_dirs (key_file,
|
|
|
b31790 |
desktop_file,
|
|
|
b31790 |
(const char **) app_dirs,
|
|
|
b31790 |
&app_path,
|
|
|
b31790 |
G_KEY_FILE_NONE,
|
|
|
b31790 |
NULL);
|
|
|
b31790 |
if (app_path != NULL) {
|
|
|
b31790 |
g_debug ("GsmUtil: found in XDG dirs: '%s'", app_path);
|
|
|
b31790 |
}
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
g_free (desktop_file);
|
|
|
b31790 |
g_key_file_free (key_file);
|
|
|
b31790 |
|
|
|
b31790 |
g_strfreev (app_dirs);
|
|
|
b31790 |
|
|
|
b31790 |
return app_path;
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
static gboolean
|
|
|
b31790 |
ensure_dir_exists (const char *dir)
|
|
|
b31790 |
{
|
|
|
b31790 |
+ if (g_file_test (dir, G_FILE_TEST_IS_DIR))
|
|
|
b31790 |
+ return TRUE;
|
|
|
b31790 |
+
|
|
|
f47161 |
if (g_mkdir_with_parents (dir, 0700) == 0)
|
|
|
b31790 |
return TRUE;
|
|
|
b31790 |
|
|
|
b31790 |
+ if (errno == EEXIST)
|
|
|
b31790 |
+ return g_file_test (dir, G_FILE_TEST_IS_DIR);
|
|
|
b31790 |
+
|
|
|
b31790 |
g_warning ("GsmSessionSave: Failed to create directory %s: %s", dir, strerror (errno));
|
|
|
b31790 |
|
|
|
b31790 |
return FALSE;
|
|
|
b31790 |
}
|
|
|
b31790 |
|
|
|
b31790 |
gchar *
|
|
|
b31790 |
gsm_util_get_empty_tmp_session_dir (void)
|
|
|
b31790 |
{
|
|
|
b31790 |
char *tmp;
|
|
|
b31790 |
gboolean exists;
|
|
|
b31790 |
|
|
|
b31790 |
tmp = g_build_filename (g_get_user_config_dir (),
|
|
|
b31790 |
"gnome-session",
|
|
|
b31790 |
"saved-session.new",
|
|
|
b31790 |
NULL);
|
|
|
b31790 |
|
|
|
b31790 |
exists = ensure_dir_exists (tmp);
|
|
|
b31790 |
|
|
|
b31790 |
if (G_UNLIKELY (!exists)) {
|
|
|
b31790 |
g_warning ("GsmSessionSave: could not create directory for saved session: %s", tmp);
|
|
|
b31790 |
g_free (tmp);
|
|
|
b31790 |
return NULL;
|
|
|
b31790 |
} else {
|
|
|
b31790 |
/* make sure it's empty */
|
|
|
b31790 |
GDir *dir;
|
|
|
b31790 |
const char *filename;
|
|
|
b31790 |
|
|
|
b31790 |
dir = g_dir_open (tmp, 0, NULL);
|
|
|
b31790 |
if (dir) {
|
|
|
b31790 |
while ((filename = g_dir_read_name (dir))) {
|
|
|
b31790 |
--
|
|
|
f47161 |
2.17.0
|
|
|
b31790 |
|