diff options
author | Ivan Furs <i.furs@samsung.com> | 2017-01-12 16:24:31 -0800 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2017-01-12 16:24:34 -0800 |
commit | 12ee780653f7d4748fa682e3c9bc0401382721b6 (patch) | |
tree | 5c8d5c512fc56622fcd48467b4fa3d1845fc4c15 /src/lib | |
parent | 1f9e915b5a001b4f4845defda559434b35588e96 (diff) |
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>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ecore_file/ecore_file.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/ecore_file/ecore_file.c b/src/lib/ecore_file/ecore_file.c index dd53db1db9..6e341ea640 100644 --- a/src/lib/ecore_file/ecore_file.c +++ b/src/lib/ecore_file/ecore_file.c | |||
@@ -508,6 +508,21 @@ ecore_file_mv(const char *src, const char *dst) | |||
508 | goto PASS; | 508 | goto PASS; |
509 | } | 509 | } |
510 | } | 510 | } |
511 | #ifdef _WIN32 | ||
512 | if (errno == EEXIST) | ||
513 | { | ||
514 | struct _stat s; | ||
515 | _stat(dst, &s); | ||
516 | if (_S_IFREG & s.st_mode) | ||
517 | { | ||
518 | ecore_file_unlink(dst); | ||
519 | if (rename(src, dst)) | ||
520 | { | ||
521 | return EINA_TRUE; | ||
522 | } | ||
523 | } | ||
524 | } | ||
525 | #endif | ||
511 | goto FAIL; | 526 | goto FAIL; |
512 | } | 527 | } |
513 | 528 | ||