forked from enlightenment/efl
ecore_file: add case to properly rename a file in Windows
Summary: If the file with a new path was created and 'rename' wants to replace the old path to the new path. 'rename' will return: Windows 7: -1 (errno=EEXIST) (EEXIST == 17) Ubuntu: 0 **EEXIST** **Ubuntu**: The link named by new is a directory that is not an empty directory. (https://linux.die.net/man/3/rename) **Windows 7**: Files exist. An attempt has been made to create a file that already exists. For example, the _O_CREAT and _O_EXCL flags are specified in an _open call, but the named file already exists.(https://msdn.microsoft.com/en-us/library/5814770t.aspx) Test Plan: **Sample code to rename in Linux and Windows if the file with the new name already exists:** int main() { const char *_old = "old"; const char *_new = "new"; int fd1 = open(_old, O_CREAT); close(fd1); int fd2 = open(_new, O_CREAT); close(fd2); printf("rename:\t%s -> %s\n", _old, _new); int r = rename(_old, _new); if (r == 0) { printf("GOOD\n"); } else { printf("CODE ERROR:\n" ); printf(" -rename...: %d\n", r ); printf(" -errno....: %d\n", errno); } return 0; } Reviewers: raster, vtorri, jpeg, NikaWhite, reutskiy.v.v, an.kroitor, cedric Reviewed By: cedric Subscribers: artem.popov, cedric, jpeg Tags: #efl, #windows Differential Revision: https://phab.enlightenment.org/D4561 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
parent
1f9e915b5a
commit
12ee780653
|
@ -508,6 +508,21 @@ ecore_file_mv(const char *src, const char *dst)
|
|||
goto PASS;
|
||||
}
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (errno == EEXIST)
|
||||
{
|
||||
struct _stat s;
|
||||
_stat(dst, &s);
|
||||
if (_S_IFREG & s.st_mode)
|
||||
{
|
||||
ecore_file_unlink(dst);
|
||||
if (rename(src, dst))
|
||||
{
|
||||
return EINA_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue