fuse: Use query_info_on_{read,write} if a stream is open

If a stream is open and it supports query_info_on_{read,write}, use that
in preference to querying the file using the path.  This causes the
correct information to be retrieved when g_file_replace is implemented
by writing to a temporary file, rather than the information of the
yet-to-be-replaced file.

https://bugzilla.gnome.org/show_bug.cgi?id=632296
fuse: Truncate stream rather than path if possible

When truncating, if a writable stream is open, truncate that rather than
using g_file_replace on the path since that fails to have the desired
effect if replace is implemented by writing to a temporary and then
renaming.

https://bugzilla.gnome.org/show_bug.cgi?id=632296
http: Always set the file type to regular

Always set the file type to regular so that querying the type of an
input stream gives the expected result.

https://bugzilla.gnome.org/show_bug.cgi?id=632296
fuse: Don't g_file_append_to unless O_APPEND is given

Because g_file_append_to opens an output stream that can only append
regardless of the seek position, only use g_file_append_to when O_APPEND
is actually specified.  This prevents file corruption when the mode is
O_WRONLY or O_RDWR without O_APPEND.

Note that this means opening a file with a bare O_WRONLY or O_RDWR
returns ENOTSUP since there is no equivalent in gvfs.

Furthermore, don't attempt to seek when the file mode is O_APPEND since
this is unnecessary.

https://bugzilla.gnome.org/show_bug.cgi?id=632296
fuse: Track the size of open files properly

Previously, if a getattr() for an open file could not get the size
information, the file position was returned as the size.  This is
incorrect if seek or ftruncate had previously been used on the stream.

Instead, track the size of the open file and return this value.  In
addition, use this size in preference to the size returned by
g_file_query_info() if a stream is open (this only happens if the stream
doesn't support g_file_query_info_on_write()) since the tracked size is
more likely to be correct due to implementing g_file_replace by writing
to a temporary file.  Tracking the size is only necessary for files
which are created or opened with O_TRUNC since files opened with
O_APPEND will be appended in-place.

https://bugzilla.gnome.org/show_bug.cgi?id=632296
fuse: Close stream on release rather than flush

Before, if an application created, dup()ed the fd and then closed it,
the stream would be closed.  When attempting to write to the original
fd, reopening the stream would fail since it is an error to open an
existing file without either truncating it or appending to it.

Close the stream on release() rather than flush() to fix this since
release() is called only once per open/create rather than for each
close.  Since g_output_stream_flush() is called after every write,
flush() and fsync() are unnecessary.

https://bugzilla.gnome.org/show_bug.cgi?id=632296
fuse: Pass the correct flags when reopening output stream

If a file is open for reading and writing, ensure to pass the O_APPEND
flag if necessary when reopening the output stream.  This allows a
write-read-write sequence to work properly if the file is opened for
O_APPEND.  The O_TRUNC flag is not passed since this would cause a
write-read-write sequence to truncate the file on the second write.  As
it is, the second write fails with ENOTSUP since this kind of operation
is not supported by GVFS.

https://bugzilla.gnome.org/show_bug.cgi?id=632296