X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/af04e282e301efc9a573a5d514a4fed98c566e33..c675b440b60e68cd6eab35764858cc1b4bb2cb5b:/src/smpi/internals/smpi_global.cpp diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 741fc1033f..33efd33383 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -20,8 +20,10 @@ #include #include /* split */ #include +#include #include #include /* intmax_t */ +#include /* strerror */ #include #include #include @@ -360,8 +362,10 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of { int fdin = open(src.c_str(), O_RDONLY); xbt_assert(fdin >= 0, "Cannot read from %s. Please make sure that the file exists and is executable.", src.c_str()); - int fdout = open(target.c_str(), O_CREAT | O_RDWR, S_IRWXU); - xbt_assert(fdout >= 0, "Cannot write into %s", target.c_str()); + XBT_ATTRIB_UNUSED int unlink_status = unlink(target.c_str()); + xbt_assert(unlink_status == 0 || errno == ENOENT, "Failed to unlink file %s: %s", target.c_str(), strerror(errno)); + int fdout = open(target.c_str(), O_CREAT | O_RDWR | O_EXCL, S_IRWXU); + xbt_assert(fdout >= 0, "Cannot write into %s: %s", target.c_str(), strerror(errno)); XBT_DEBUG("Copy %" PRIdMAX " bytes into %s", static_cast(fdin_size), target.c_str()); #if SG_HAVE_SENDFILE