Unlink created image file if fallocate() or copying failed (#363)

* Unlink created image file if fallocate() failed

* Also delete destination file after copying if something goes wrong
This commit is contained in:
Uwe Seimet 2021-10-22 03:17:58 +02:00 committed by GitHub
parent 269b718ec7
commit ac4abbbe73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,6 +151,8 @@ bool RascsiImage::CreateImage(int fd, const PbCommand& command)
if (fallocate(image_fd, 0, 0, len) == -1) {
close(image_fd);
unlink(filename.c_str());
return ReturnStatus(fd, false, "Can't allocate space for image file '" + filename + "': " + string(strerror(errno)));
}
@ -297,6 +299,8 @@ bool RascsiImage::CopyImage(int fd, const PbCommand& command)
close(fd_dst);
close(fd_src);
unlink(to.c_str());
return ReturnStatus(fd, false, "Can't copy image file '" + from + "' to '" + to + "': " + string(strerror(errno)));
}