Skip to content

Commit

Permalink
fix #9791: use SystemImpl__rename instead of rename (#9792)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Nov 28, 2022
1 parent 4525d60 commit 7c43b35
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/runtime/om_curl.c
Expand Up @@ -132,7 +132,7 @@ int om_curl_multi_download(void *urlPathList, int maxParallel)
}
} else {
fclose(fout);
if (rename(MMC_STRINGDATA(p->tmpFilename), MMC_STRINGDATA(p->filename))) {
if (omc_rename(MMC_STRINGDATA(p->tmpFilename), MMC_STRINGDATA(p->filename))) {
const char *msgs[3] = {strerror(errno), MMC_STRINGDATA(p->filename), MMC_STRINGDATA(p->tmpFilename)};
c_add_message(NULL, -1, ErrorType_runtime,ErrorLevel_error, "Failed to rename file after downloading with curl %s %s: %s", msgs, 3);
}
Expand Down
5 changes: 1 addition & 4 deletions OMCompiler/Compiler/runtime/systemimpl.c
Expand Up @@ -2992,10 +2992,7 @@ int SystemImpl__fileContentsEqual(const char *file1, const char *file2)

int SystemImpl__rename(const char *source, const char *dest)
{
#if defined(__MINGW32__) || defined(_MSC_VER)
return MoveFileEx(source, dest, MOVEFILE_REPLACE_EXISTING);
#endif
return 0==rename(source,dest);
return omc_rename(source, dest);
}

char* SystemImpl__ctime(double time)
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/runtime/systemimpl.h
Expand Up @@ -92,6 +92,7 @@ extern int SystemImpl__setLDFlags(const char *str);
extern char* SystemImpl__pwd(void);
extern int SystemImpl__regularFileExists(const char* str);
extern int SystemImpl__removeFile(const char* filename);
extern int SystemImpl__rename(const char *source, const char *dest);
extern const char* SystemImpl__basename(const char *str);
extern int SystemImpl__systemCall(const char* str, const char* outFile);
extern void* SystemImpl__systemCallParallel(void *lst, int numThreads);
Expand Down
10 changes: 8 additions & 2 deletions OMCompiler/SimulationRuntime/c/util/omc_file.c
Expand Up @@ -217,8 +217,7 @@ int omc_file_exists(const char* filename) {
* @param filename File name
* @return int 0 on success, -1 on error.
*/
int omc_unlink(const char *filename)
{
int omc_unlink(const char *filename) {
int result = 0;
#if defined(__MINGW32__) || defined(_MSC_VER)
wchar_t* unicodeFilename = omc_multibyte_to_wchar_str(filename);
Expand All @@ -241,6 +240,13 @@ int omc_unlink(const char *filename)
return result;
}

int omc_rename(const char *source, const char *dest) {
#if defined(__MINGW32__) || defined(_MSC_VER)
return MoveFileEx(source, dest, MOVEFILE_REPLACE_EXISTING);
#endif
return 0==rename(source,dest);
}

#if defined(__MINGW32__) || defined(_MSC_VER)
/**
* @brief Return long absolute path from given path.
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/SimulationRuntime/c/util/omc_file.h
Expand Up @@ -90,6 +90,7 @@ int omc_lstat(const char *filename, omc_stat_t *statbuf);
int omc_file_exists(const char* filename);

int omc_unlink(const char *filename);
int omc_rename(const char *source, const char *dest);

#if defined(__MINGW32__) || defined(_MSC_VER)
wchar_t* longabspath(wchar_t* unicodePath);
Expand Down

0 comments on commit 7c43b35

Please sign in to comment.