6 releases (stable)
| 1.2.0 | Jul 10, 2025 |
|---|---|
| 1.1.1 | Jul 10, 2025 |
| 1.0.0 | Jul 10, 2025 |
| 0.1.1 | Nov 12, 2022 |
| 0.1.0 | Nov 11, 2022 |
#445 in Development tools
179 downloads per month
11KB
167 lines
Copies the currently running program into a temporary location
This crate copies the currently running executable into a temporary location and returns the path to that executable. This allows you to (for example):
- Compile a program statically using something like musl
- Create a copy of that program while it's running
- Run Docker from your original program, mounting the copy as a Docker volume mount
- Run the copied program from within the Dockerized environment.
Because this library uses NamedTempFile via Builder to generate a temporary location,
the following security restrictions apply to Replicate:
- The copy has a short lifetime and your temporary file cleaner is sane (doesn’t delete recently accessed files).
- You trust every user on your system (i.e. you are the only user).
- You have disabled your system’s temporary file cleaner or verified that your system doesn’t have a temporary file cleaner.
replicate
replicate is a library that:
- copies the currently running program to a temporary file
- (Unix-only) makes that file executable
- returns a path object to the temporary file, that cleans up the temporary file when dropped.
It's intended to be used by musl-compiled programs which can run inside Docker containers; by creating a copy and then volume-mounting that program within the Docker container, or by using the program in a named build-context.
Examples
use replicate::Replicate;
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let copy = Replicate::new()?;
println!("My copy's path is {}", copy.display());
Ok(())
}
Additional examples are in the examples directory.
Dependencies
~1.7–6.5MB
~142K SLoC