Commit Diff


commit - f970685c28a69b4ad4cb94b882bec962b274022f
commit + 51130c027d3d769ca63c1d9051231791ad5f2f39
blob - 811852390009b439b1fa0ba6e06034eaee832a4f
blob + cbb6de133806483e00d1d51b5acffb2ebf00b01b
--- lib/object_create.c
+++ lib/object_create.c
@@ -18,6 +18,7 @@
 #include <sys/stat.h>
 #include <sys/queue.h>
 
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -128,8 +129,21 @@ got_object_blob_create(struct got_object_id **id, cons
 		goto done;
 
 	err = got_opentemp_named(&outpath, &outfile, objpath);
-	if (err)
-		goto done;
+	if (err) {
+		char *parent_path;
+		if (!(err->code == GOT_ERR_ERRNO && errno == ENOENT))
+			goto done;
+		err = got_path_dirname(&parent_path, objpath);
+		if (err)
+			goto done;
+		err = got_path_mkdir(parent_path);
+		free(parent_path);
+		if (err)
+			goto done;
+		err = got_opentemp_named(&outpath, &outfile, objpath);
+		if (err)
+			goto done;
+	}
 
 	err = got_deflate_to_file(&outlen, blobfile, outfile);
 	if (err)