summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2013-11-13 16:59:32 +0200
committerRoss Lagerwall <rosslagerwall@gmail.com>2013-12-05 23:51:32 +0000
commitd274d614677ad987d795925d7f15cab582b9e17d (patch)
treea980864314b05548aa8a352fd2270cd6c775c38e
parent07d802db0b73fc345a53db3c6d65d9912f9cbb5a (diff)
downloadgvfs-d274d614677ad987d795925d7f15cab582b9e17d.tar.gz
gphoto2: Implement truncate support for output streams
https://bugzilla.gnome.org/show_bug.cgi?id=573837
-rw-r--r--daemon/gvfsbackendgphoto2.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/daemon/gvfsbackendgphoto2.c b/daemon/gvfsbackendgphoto2.c
index 63a451b3..ad4bd2f1 100644
--- a/daemon/gvfsbackendgphoto2.c
+++ b/daemon/gvfsbackendgphoto2.c
@@ -3052,6 +3052,7 @@ do_create_internal (GVfsBackend *backend,
g_vfs_job_open_for_write_set_handle (job, handle);
g_vfs_job_open_for_write_set_can_seek (job, TRUE);
+ g_vfs_job_open_for_write_set_can_truncate (job, TRUE);
gphoto2_backend->open_write_handles = g_list_prepend (gphoto2_backend->open_write_handles, handle);
@@ -3228,6 +3229,40 @@ do_seek_on_write (GVfsBackend *backend,
/* ------------------------------------------------------------------------------------------------- */
+static void
+do_truncate (GVfsBackend *backend,
+ GVfsJobTruncate *job,
+ GVfsBackendHandle _handle,
+ goffset size)
+{
+ WriteHandle *handle = _handle;
+
+ DEBUG ("truncate() %p, '%s', %ld bytes", handle, handle->filename, size);
+
+ /* ensure we have enough room */
+ if (size > handle->allocated_size)
+ {
+ unsigned long int new_allocated_size;
+ new_allocated_size = (size / WRITE_INCREMENT + 1) * WRITE_INCREMENT;
+ handle->data = g_realloc (handle->data, new_allocated_size);
+ handle->allocated_size = new_allocated_size;
+ DEBUG (" allocated_size is now %ld bytes)", handle->allocated_size);
+ }
+
+
+ if (size > handle->size)
+ memset(handle->data + handle->size, 0, size - handle->size);
+
+ handle->size = size;
+
+ /* this will make us dirty */
+ handle->is_dirty = TRUE;
+
+ g_vfs_job_succeeded (G_VFS_JOB (job));
+}
+
+/* ------------------------------------------------------------------------------------------------- */
+
/* this functions updates the device with the data currently in write_handle */
static int
commit_write_handle (GVfsBackendGphoto2 *gphoto2_backend, WriteHandle *write_handle)
@@ -3586,6 +3621,7 @@ g_vfs_backend_gphoto2_class_init (GVfsBackendGphoto2Class *klass)
backend_class->write = do_write;
backend_class->close_write = do_close_write;
backend_class->seek_on_write = do_seek_on_write;
+ backend_class->truncate = do_truncate;
backend_class->move = do_move;
backend_class->create_dir_monitor = do_create_dir_monitor;
backend_class->create_file_monitor = do_create_file_monitor;