From de0b5f0d860559f1dea01b95fd90d6cffbfbb86f Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 27 Jul 2017 20:42:28 +0100 Subject: [PATCH] Allow writing to currently executing files --- brick/uf2daemon/fat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brick/uf2daemon/fat.c b/brick/uf2daemon/fat.c index 04370755..df5fc210 100644 --- a/brick/uf2daemon/fat.c +++ b/brick/uf2daemon/fat.c @@ -21,6 +21,7 @@ #include #include #include +#include #define max(a, b) \ ({ \ @@ -740,6 +741,10 @@ void write_block(uint32_t block_no, uint8_t *data) { *p = '/'; int fd = open(fn, O_WRONLY | O_CREAT, 0777); + if (fd < 0 && errno == ETXTBSY) { + unlink(fn); + fd = open(fn, O_WRONLY | O_CREAT, 0777); + } if (fd >= 0) { ftruncate(fd, bl->fileSize); lseek(fd, bl->targetAddr, SEEK_SET);