an efficient binary archive format
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cleanup logging

zach eb520ff7 db49b22c

+26 -16
+26 -16
src/bin/bindle.rs
··· 59 59 /// Use zstd compression 60 60 #[arg(short, long)] 61 61 compress: bool, 62 + /// Append to existing file 63 + #[arg(short, long)] 64 + append: bool, 62 65 }, 63 66 64 67 /// Unpack the archive to a local directory ··· 83 86 let cli = Cli::parse(); 84 87 85 88 if let Err(e) = handle_command(cli.command) { 86 - eprintln!("Operation failed: {}", e); 89 + eprintln!("ERROR {}", e); 87 90 process::exit(1); 88 91 } 89 92 } 90 93 91 94 fn handle_command(command: Commands) -> io::Result<()> { 92 - let init = |path| match Bindle::open(path) { 95 + let init = |path: PathBuf| match Bindle::open(&path) { 93 96 Ok(bindle) => bindle, 94 97 Err(e) => { 95 - eprintln!("Error: unable to open '{}'", e); 98 + eprintln!("ERROR unable to open {}: {}", path.display(), e); 96 99 process::exit(1); 97 100 } 98 101 }; 99 102 100 103 match command { 101 104 Commands::List { bindle_file } => { 102 - let b = init(bindle_file); 103 - if b.is_empty() { 104 - println!("Archive is empty"); 105 - return Ok(()); 106 - } 107 - 108 105 println!( 109 106 "{:<30} {:<12} {:<12} {:<10}", 110 107 "NAME", "SIZE", "PACKED", "RATIO" 111 108 ); 112 109 println!("{}", "-".repeat(70)); 110 + if !bindle_file.exists() { 111 + return Ok(()); 112 + } 113 + let b = init(bindle_file); 113 114 114 115 for (name, entry) in b.index().iter() { 115 116 let size = entry.uncompressed_size(); ··· 131 132 compress, 132 133 bindle_file, 133 134 } => { 134 - let mut b = init(bindle_file); 135 + let mut b = init(bindle_file.clone()); 135 136 let data = std::fs::read(&file_path)?; 136 137 137 - println!("Adding '{}' ({} bytes)", name, data.len()); 138 - 139 138 b.add( 140 139 &name, 141 140 &data, ··· 145 144 Compress::None 146 145 }, 147 146 )?; 147 + println!( 148 + "ADD '{}' -> {} ({} bytes)", 149 + name, 150 + bindle_file.display(), 151 + data.len() 152 + ); 148 153 b.save()?; 149 154 150 155 println!("OK"); 151 156 } 152 157 153 158 Commands::Cat { name, bindle_file } => { 154 - let b = init(bindle_file); 159 + let b = init(bindle_file.clone()); 155 160 match b.read(&name) { 156 161 Some(data) => { 157 162 io::stdout().write_all(&data)?; ··· 159 164 None => { 160 165 return Err(io::Error::new( 161 166 io::ErrorKind::NotFound, 162 - format!("Entry '{}' not found in archive", name), 167 + format!("ERROR '{}' not found in {}", name, bindle_file.display()), 163 168 )); 164 169 } 165 170 } ··· 169 174 bindle_file, 170 175 src_dir, 171 176 compress, 177 + append, 172 178 } => { 179 + println!("PACK {} -> {}", src_dir.display(), bindle_file.display()); 173 180 let mut b = init(bindle_file); 174 - println!("Packing '{}'", src_dir.display()); 181 + if !append { 182 + b.clear(); 183 + } 175 184 b.pack( 176 185 src_dir, 177 186 if compress { ··· 188 197 bindle_file, 189 198 dest_dir, 190 199 } => { 200 + println!("UNPACK {} -> {}", bindle_file.display(), dest_dir.display()); 191 201 let b = init(bindle_file); 192 - println!("Unpacking to '{}'", dest_dir.display()); 193 202 b.unpack(dest_dir)?; 194 203 println!("OK"); 195 204 } 196 205 197 206 Commands::Vacuum { bindle_file } => { 207 + println!("VACUUM {}", bindle_file.display()); 198 208 let mut b = init(bindle_file); 199 209 b.vacuum()?; 200 210 println!("OK");