diff mbox series

Create output directory for -o option

Message ID 20201223095132.580761-1-sbabic@denx.de
State Accepted
Headers show
Series Create output directory for -o option | expand

Commit Message

Stefano Babic Dec. 23, 2020, 9:51 a.m. UTC
Try to create destination directory when -o parameter is given.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/stream_interface.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/core/stream_interface.c b/core/stream_interface.c
index 6d32998..d85a533 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -455,8 +455,16 @@  static int save_stream(int fdin, struct swupdate_cfg *software)
 	lseek(tmpfd, 0, SEEK_SET);
 
 	fdout = openfileoutput(software->output);
-	if (fdout < 0)
-		return -1;
+	/*
+	 * Try to create directory if file cannot be opened
+	 */
+	if (fdout < 0) {
+		if (mkpath(software->output, 0755))
+			return -1;
+		fdout = openfileoutput(software->output);
+		if (fdout < 0)
+			return -1;
+	}
 
 	ret = cpfiles(tmpfd, fdout, 0);
 	if (ret < 0)