]>
git.proxmox.com Git - proxmox-backup.git/blob - examples/dynamic-files.rs
1 use anyhow
::{bail, Error}
;
4 use std
::path
::PathBuf
;
7 // tar handle files that shrink during backup, by simply padding with zeros.
9 // this binary run multiple thread which writes some large files, then truncates
12 // # tar cf test.tar ./dyntest1/
13 // tar: dyntest1/testfile0.dat: File shrank by 2768972800 bytes; padding with zeros
14 // tar: dyntest1/testfile17.dat: File shrank by 2899853312 bytes; padding with zeros
15 // tar: dyntest1/testfile2.dat: File shrank by 3093422080 bytes; padding with zeros
16 // tar: dyntest1/testfile7.dat: File shrank by 2833252864 bytes; padding with zeros
18 // # pxar create test.pxar ./dyntest1/
19 // Error: detected shrunk file "./dyntest1/testfile0.dat" (22020096 < 12679380992)
21 fn create_large_file(path
: PathBuf
) {
23 println
!("TEST {:?}", path
);
25 let mut file
= std
::fs
::OpenOptions
::new()
28 .open(&path
).unwrap();
30 let buffer
= vec
![0u8; 64*1024];
34 file
.write_all(&buffer
).unwrap();
36 file
.sync_all().unwrap();
37 //println!("TRUNCATE {:?}", path);
38 file
.set_len(0).unwrap();
42 fn main() -> Result
<(), Error
> {
44 let base
= PathBuf
::from("dyntest1");
45 let _
= std
::fs
::create_dir(&base
);
47 let mut handles
= vec
![];
49 let base
= base
.clone();
50 handles
.push(thread
::spawn(move || {
51 create_large_file(base
.join(format
!("testfile{}.dat", i
)));
56 if h
.join().is_err() {