GNOME Bugzilla – Bug 533547
GIO doesn't permit seekable binary readwrite access to existing files.
Last modified: 2009-11-24 13:17:50 UTC
Using GIO I have found it possible to create a new file and have seekable readwrite access to it, after having flushed and closed that file there is no way to open two new streams that I can use for new read write access. This should be possible at least for local files. It might be that the new call to do this is only available for some backends, like the local one. At the moment I am using a stopgap measure with a hacked GIO in GEGL to support resumable swap files, and would hope not having to port the code away from GIO again.
Created attachment 111039 [details] [review] workaround patch to allow seekable readwrite access to exsisting file. Attached the code I cobbled together when I realized what my "bugs" were due to, this isn't a solution that is feasible but I've used it and it works so the rest of the infrastructure is up to handling the task at least.
I suspect you already answered this question elsewhere, but why can't you open it for writing (append) and reading separately?
Opening the file for append would not allow seeking to an already existing position in the file, only to positions after the original end of file.
A potential API addition could probably be a call like: GFileOutputStream *g_file_write (GFile *file, GCancellable *cancellable, GError **error); That would open an output stream for an already existing file that allows overwriting data at given positions. For my usage I need another simultanous intput stream for the same file to reflect the changes when the output stream is flushed.
The main target for the GFile API is for "document" like applications, that read the file on open, streaming conversion to an internal format and then write it on save. We don't want such apps to accidentally open a file in read-write mode (common with the gnome-vfs api), since that is not supportable on the great majority of backends. However, I wouldn't oppose adding an API that let you open a file in read-write mode, returning a new kind of object that has getters for the input and the output stream. As long as its clearly marked as not supported for most backends.
Such an API would fit the purposes where I need this. At the moment I am considering to move the affected code away from GIO again since in the end my usage for it will end up mmapping the data and thus probably should be doing all of this on a lower level of abstraction.
this is now availible w/ GIOStream, g_file_open_readwrite, etc.