FileT.replaceContents

Replaces the contents of @file with @contents of @length bytes.

If @etag is specified (not %NULL), any existing file must have that etag, or the error %G_IO_ERROR_WRONG_ETAG will be returned.

If @make_backup is %TRUE, this function will attempt to make a backup of @file. Internally, it uses g_file_replace(), so will try to replace the file contents in the safest way possible. For example, atomic renames are used when replacing local files’ contents.

If @cancellable is not %NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.

The returned @new_etag can be used to verify that the file hasn't changed the next time it is saved over.

template FileT(TStruct)
bool
replaceContents
(
string contents
,
string etag
,,
GFileCreateFlags flags
,
out string newEtag
,
Cancellable cancellable
)

Parameters

contents string

a string containing the new contents for @file

etag string

the old [entity-tag][gfile-etag] for the document, or %NULL

makeBackup bool

%TRUE if a backup should be created

flags GFileCreateFlags

a set of #GFileCreateFlags

newEtag string

a location to a new [entity tag][gfile-etag] for the document. This should be freed with g_free() when no longer needed, or %NULL

cancellable Cancellable

optional #GCancellable object, %NULL to ignore

Return Value

Type: bool

%TRUE if successful. If an error has occurred, this function will return %FALSE and set @error appropriately if present.

Throws

GException on failure.

Meta