From 4e1988997a3a08e649f806d26024921d5d3d5053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Val=C3=A9rio?= Date: Sun, 6 Dec 2020 18:39:04 +0000 Subject: [PATCH] step sixty one: push, send only missing objects --- src/data.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/data.rs b/src/data.rs index 7c9a7ca..0e0f74a 100644 --- a/src/data.rs +++ b/src/data.rs @@ -176,12 +176,18 @@ pub fn fetch_object_if_missing(oid: String, remote_git_dir: String) { pub fn push_object(oid: String, remote_git_dir: String) { let rgit_remote = remote_git_dir + "/.rgit"; + let remote_object = format!("{}/objects/{}", rgit_remote, oid.clone()); + + if Path::new(&remote_object).exists() { + // Only push object if it doesn't exist. + // Different implementation from the tutorial, the end result should be + // the same. + return; + } + let dir = RGIT_DIR.lock().unwrap().to_owned(); - fs::copy( - format!("{}/objects/{}", dir, oid), - format!("{}/objects/{}", rgit_remote, oid.clone()), - ) - .expect(format!("Failed to push {}", oid).as_str()); + fs::copy(format!("{}/objects/{}", dir, oid), remote_object) + .expect(format!("Failed to push {}", oid).as_str()); } fn object_exists(oid: String) -> bool {