A tool to sync music with your favorite devices
0
fork

Configure Feed

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

cmd/sync: hardlink instead of copy

Add `--link' flag when using `sync', so that target becomes an ordered
view of your library.

Gee Sawra f1875297 e9b3cace

+36 -18
+36 -18
src/cmd/sync.rs
··· 28 28 /// print what tracks would be copied over. 29 29 #[arg(long, default_value_t = false)] 30 30 pub dry_run: bool, 31 + 32 + /// Instead of copying the files over to the specified destination, create an hardlink. 33 + #[arg(long, default_value_t = false)] 34 + pub link: bool, 31 35 } 32 36 33 37 impl Args { ··· 92 96 run_delete(&dest_db, &dest_dir, reverse_diff, filters.as_ref()).await? 93 97 } 94 98 95 - run_copy(&local_db, &dest_db, &dest_dir, diff, filters.as_ref()).await?; 99 + run_copy( 100 + &local_db, 101 + &dest_db, 102 + &dest_dir, 103 + diff, 104 + filters.as_ref(), 105 + args.link, 106 + ) 107 + .await?; 96 108 97 109 Ok(()) 98 110 } ··· 215 227 dest_dir: &String, 216 228 diff: Vec<String>, 217 229 filters: Option<&Vec<crate::filter::ScriptRuntime>>, 230 + link: bool, 218 231 ) -> Result<()> { 219 232 let diff_len = diff.len(); 220 233 ··· 235 248 total_bar.tick(); 236 249 237 250 for track in tracks { 238 - copy(track, &dest_db, &dest_dir, &mp).await?; 251 + copy(track, &dest_db, &dest_dir, &mp, link).await?; 239 252 total_bar.inc(1); 240 253 } 241 254 ··· 357 370 dest_db: &db::Instance, 358 371 dest_dir: &String, 359 372 mp: &indicatif::MultiProgress, 373 + link: bool, 360 374 ) -> Result<()> { 361 375 let track_storage_path = track.storage_path(&dest_dir); 362 376 let sp = std::path::Path::new(&track_storage_path); ··· 405 419 406 420 let opts = CopyOptions::new().overwrite(true); 407 421 408 - match copy_with_progress( 409 - track.file_path.clone(), 410 - track_storage_path.clone(), 411 - &opts, 412 - |ph| { 413 - bar.set_position(ph.copied_bytes); 414 - }, 415 - ) { 416 - std::result::Result::Ok(_) => {} 417 - Err(err) => { 418 - return Err(error::Error::CopyError(err)).with_context(|| { 419 - format!("Cannot copy {} to {}", track.file_path, track_storage_path) 420 - }); 421 - } 422 - }; 423 - // .with_context(|| format!("Cannot copy {} to {}", track.file_path, track_storage_path))?; 422 + if link { 423 + std::fs::hard_link(track.file_path.clone(), track_storage_path.clone())?; 424 + } else { 425 + match copy_with_progress( 426 + track.file_path.clone(), 427 + track_storage_path.clone(), 428 + &opts, 429 + |ph| { 430 + bar.set_position(ph.copied_bytes); 431 + }, 432 + ) { 433 + std::result::Result::Ok(_) => {} 434 + Err(err) => { 435 + return Err(error::Error::CopyError(err)).with_context(|| { 436 + format!("Cannot copy {} to {}", track.file_path, track_storage_path) 437 + }); 438 + } 439 + }; 440 + // .with_context(|| format!("Cannot copy {} to {}", track.file_path, track_storage_path))?; 441 + } 424 442 425 443 // step 3: update the destination track with the new state 426 444 dest_track.file_state = crate::model::FileState::Copied;