Struct git_tempfile::Handle[][src]

pub struct Handle<Marker: Debug> { /* fields omitted */ }
Expand description

A registered temporary file which will delete itself on drop or if the program is receiving signals that should cause it to terminate.

Note

Signals interrupting the calling thread right after taking ownership of the registered tempfile will cause all but this tempfile to be removed automatically. In the common case it will persist on disk as destructors were not called or didn’t get to remove the file.

In the best case the file is a true temporary with a non-clashing name that ‘only’ fills up the disk, in the worst case the temporary file is used as a lock file which may leave the repository in a locked state forever.

This kind of raciness exists whenever take() is used and can’t be circumvented.

Implementations

Persist this tempfile to replace the file at the given path if necessary, in a way that recovers the original instance on error or returns the open now persisted former tempfile. Note that it might not exist anymore if an interrupt handler managed to steal it and allowed the program to return to its normal flow.

Persist this tempfile to replace the file at the given path if necessary, in a way that recovers the original instance on error.

Creation and ownership transfer

Create a registered tempfile at the given path, where path includes the desired filename and close it immediately.

Depending on the directory configuration, intermediate directories will be created, and depending on cleanup empty intermediate directories will be removed.

Take ownership of the temporary file path, which deletes it when dropped without persisting it beforehand.

It’s a theoretical possibility that the file isn’t present anymore if signals interfere, hence the Option

Creation and ownership transfer

Create a registered tempfile at the given path, where path includes the desired filename.

Depending on the directory configuration, intermediate directories will be created, and depending on cleanup empty intermediate directories will be removed.

Create a registered tempfile within containing_directory with a name that won’t clash, and clean it up as specified with cleanup. Control how to deal with intermediate directories with directory. The temporary file is opened and can be written to using the with_mut() method.

Take ownership of the temporary file.

It’s a theoretical possibility that the file isn’t present anymore if signals interfere, hence the Option

Close the underlying file handle but keep track of the temporary file as before for automatic cleanup.

This saves system resources in situations where one opens a tempfile file at a time, writes a new value, and closes it right after to perform more updates of this kind in other tempfiles. When all succeed, they can be renamed one after another.

Mutation

Obtain a mutable handler to the underlying named tempfile and call f(&mut named_tempfile) on it.

Note that for the duration of the call, a signal interrupting the operation will cause the tempfile not to be cleaned up as it is not visible anymore to the signal handler.

Assumptions

The caller must assure that the signal handler for cleanup will be followed by an abort call so that this code won’t run again on a removed instance. An error will occur otherwise.

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Like read, except that it reads into a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

Creates a “by reference” adapter for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

🔬 This is a nightly-only experimental API. (seek_stream_len)

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. Read more

Write a buffer into this writer, returning how many bytes were written. Read more

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

Like write, except that it writes from a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Writer has an efficient write_vectored implementation. Read more

Attempts to write an entire buffer into this writer. Read more

🔬 This is a nightly-only experimental API. (write_all_vectored)

Attempts to write multiple buffers into this writer. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.