Skip to contentSkip to conversation

bundle: detect if bundle file cannot be created

PATCH In review Csaba Henk 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

Csaba Henk

author
#0 lore raw

PATCH 1/1 bundle: detect if bundle file cannot be created

bundle command silently died with no sign of failure if it could not create the bundle file. (Eg.: its path resovles to a directory, or the parent dir is sticky while file already exists and is owned by someone else.)

---
 bundle.c          |    6 ++++--
 t/t5704-bundle.sh |    7 +++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
bundle.c +4 -2
index ff97adc..3eb4ca2 100644
@@ -372,8 +372,10 @@ int create_bundle(struct bundle_header *header, const char *path,
 	close(rls.in);
 	if (finish_command(&rls))
 		return error ("pack-objects died");
-	if (!bundle_to_stdout)
-		commit_lock_file(&lock);
+	if (!bundle_to_stdout) {
+		if (commit_lock_file(&lock))
+			die_errno("cannot create bundle file");
+	}
 	return 0;
 }
 
t/t5704-bundle.sh +7 -0
index ddc3dc5..728ccd8 100755
@@ -30,6 +30,13 @@ test_expect_success 'tags can be excluded by rev-list options' '
 
 '
 
+test_expect_success 'die if bundle file cannot be created' '
+
+	mkdir adir &&
+	test_must_fail git bundle create adir --all
+
+'
+
 test_expect_failure 'bundle --stdin' '
 
 	echo master | git bundle create stdin-bundle.bdl --stdin &&
Signature · 1 line
1.7.2.2
#1 lore raw
Quoted 5 lines · Csaba Henk

bundle command silently died with no sign of failure if it could not create the bundle file. (Eg.: its path resovles to a directory, or the parent dir is sticky while file already exists and is owned by someone else.)
---

Sign-off?

Quoted 5 lines
bundle.c +0 -0
index ff97adc..3eb4ca2 100644

bundle.c int create_bundle(struct bundle_header *header, const char *path, · line 378

Quoted 9 lines
bundle.c +4 -2
@@ -372,8 +372,10 @@ int create_bundle(struct bundle_header *header, const char *path,
 	close(rls.in);
 	if (finish_command(&rls))
 		return error ("pack-objects died");
-	if (!bundle_to_stdout)
-		commit_lock_file(&lock);
+	if (!bundle_to_stdout) {
+		if (commit_lock_file(&lock))
+			die_errno("cannot create bundle file");
+	}

You would want to parrot the path given by the caller, perhaps like this?

die_errno("cannot create '%s'", path)

This function tries to report error to the caller in some places but rudely dies in some other places, so dying here is not a serious offence.

Quoted 5 lines
t/t5704-bundle.sh +0 -0
index ddc3dc5..728ccd8 100755

t/t5704-bundle.sh test_expect_success 'tags can be excluded by rev-list options' ' · line 38

Quoted 9 lines
t/t5704-bundle.sh +6 -0
@@ -30,6 +30,13 @@ test_expect_success 'tags can be excluded by rev-list options' '
 
 '
 
+test_expect_success 'die if bundle file cannot be created' '
+
+	mkdir adir &&
+	test_must_fail git bundle create adir --all
+
+'

I like it ;-)

Thanks.

author
#2 lore raw

PATCH v2 1/1 bundle: detect if bundle file cannot be created

In reply to Csaba Henk

bundle command silently died with no sign of failure if it could not create the bundle file. (Eg.: its path resovles to a directory, or the parent dir is sticky while file already exists and is owned by someone else.)

---
 bundle.c          |    6 ++++--
 t/t5704-bundle.sh |    7 +++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
bundle.c +4 -2
index ff97adc..65ea26b 100644
@@ -372,8 +372,10 @@ int create_bundle(struct bundle_header *header, const char *path,
 	close(rls.in);
 	if (finish_command(&rls))
 		return error ("pack-objects died");
-	if (!bundle_to_stdout)
-		commit_lock_file(&lock);
+	if (!bundle_to_stdout) {
+		if (commit_lock_file(&lock))
+			die_errno("cannot create '%s'", path);
+	}
 	return 0;
 }
 
t/t5704-bundle.sh +7 -0
index ddc3dc5..728ccd8 100755
@@ -30,6 +30,13 @@ test_expect_success 'tags can be excluded by rev-list options' '
 
 '
 
+test_expect_success 'die if bundle file cannot be created' '
+
+	mkdir adir &&
+	test_must_fail git bundle create adir --all
+
+'
+
 test_expect_failure 'bundle --stdin' '
 
 	echo master | git bundle create stdin-bundle.bdl --stdin &&
Signature · 1 line
1.7.2.2