aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_file
diff options
context:
space:
mode:
authorIvan Furs <i.furs@samsung.com>2017-01-12 16:24:31 -0800
committerCedric BAIL <cedric@osg.samsung.com>2017-01-12 16:24:34 -0800
commit12ee780653f7d4748fa682e3c9bc0401382721b6 (patch)
tree5c8d5c512fc56622fcd48467b4fa3d1845fc4c15 /src/lib/ecore_file
parentemotion: add support for obtaining embedded artwork from media files with gst... (diff)
downloadefl-12ee780653f7d4748fa682e3c9bc0401382721b6.tar.gz
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/ecore_file')
-rw-r--r--src/lib/ecore_file/ecore_file.c15
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)
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;
}