From 72ab669158d55f8008f4c80a882356cad42a4c53 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Mon, 20 Dec 2021 12:58:03 +0100 Subject: [PATCH] Check for existing folder --- src/raspberrypi/rascsi_image.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/raspberrypi/rascsi_image.cpp b/src/raspberrypi/rascsi_image.cpp index a6ae2c0c..971af082 100644 --- a/src/raspberrypi/rascsi_image.cpp +++ b/src/raspberrypi/rascsi_image.cpp @@ -134,8 +134,12 @@ bool RascsiImage::CreateImage(int fd, const PbCommand& command) size_t slash_position = filename.find('/'); if (slash_position != string::npos) { string folder = default_image_folder + "/" + filename.substr(0, slash_position); - if (mkdir(folder.c_str(), 0777) == -1) { - return ReturnStatus(fd, false, "Can't create folder '" + folder + "': " + strerror(errno)); + + struct stat st; + if (stat(folder.c_str(), &st)) { + if (mkdir(folder.c_str(), 0777) == -1) { + return ReturnStatus(fd, false, "Can't create folder '" + folder + "': " + strerror(errno)); + } } }