File.replaceContents

bool replaceContents(ubyte[] contents, string etag, bool makeBackup, gio.types.FileCreateFlags flags, out string newEtag, gio.cancellable.Cancellable cancellable = null)

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 [gio.types.IOErrorEnum.WrongEtag] will be returned.

If make_backup is true, this function will attempt to make a backup of file. Internally, it uses [gio.file.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 [gio.types.IOErrorEnum.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.

Parameters

contentsa string containing the new contents for file
etagthe old entity-tag for the document, or null
makeBackuptrue if a backup should be created
flagsa set of #GFileCreateFlags
newEtaga location to a new entity tag for the document. This should be freed with [glib.global.gfree] when no longer needed, or null
cancellableoptional #GCancellable object, null to ignore

Returns

true if successful. If an error has occurred, this function

will return false and set error appropriately if present.

Throws

[ErrorWrap]