[ghex] direct: Error on attempts to save to a path other than originating
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] direct: Error on attempts to save to a path other than originating
- Date: Fri, 17 Jun 2022 02:19:53 +0000 (UTC)
commit 434d4f92a4768d9b5f57c8b4c74258d9b2012fbd
Author: Logan Rathbone <poprocks gmail com>
Date: Thu Jun 16 15:08:40 2022 -0400
direct: Error on attempts to save to a path other than originating
src/hex-buffer-direct.c | 10 ++++++++++
1 file changed, 10 insertions(+)
---
diff --git a/src/hex-buffer-direct.c b/src/hex-buffer-direct.c
index 6fa8f3b..e5d6aff 100644
--- a/src/hex-buffer-direct.c
+++ b/src/hex-buffer-direct.c
@@ -62,6 +62,7 @@ struct _HexBufferDirect
GError *error; /* no custom codes; use codes from errno */
int last_errno; /* cache in case we need to re-report errno error. */
+ char *path;
int fd; /* file descriptor for direct read/write */
gint64 payload; /* size of the payload */
@@ -272,6 +273,7 @@ hex_buffer_direct_finalize (GObject *gobject)
{
close (self->fd);
}
+ g_free (self->path);
/* chain up */
G_OBJECT_CLASS(hex_buffer_direct_parent_class)->finalize (gobject);
@@ -374,6 +376,7 @@ hex_buffer_direct_set_file (HexBuffer *buf, GFile *file)
}
self->file = file;
+ self->path = g_strdup (file_path);
g_object_notify (G_OBJECT(self), "file");
return TRUE;
}
@@ -518,6 +521,13 @@ hex_buffer_direct_write_to_file (HexBuffer *buf,
g_return_val_if_fail (self->fd != -1, FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
+ if (g_strcmp0 (self->path, g_file_peek_path (file)) != 0)
+ {
+ set_error (self, _("With direct-write mode, you cannot save a file "
+ "to a path other than its originating path"));
+ return FALSE;
+ }
+
keys = (gint64 **)g_hash_table_get_keys_as_array (self->changes, &len);
/* FIXME - very inefficient - we should at least implement a sorter
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]