diff options
Diffstat (limited to 'src/lib/ecore_file')
-rw-r--r-- | src/lib/ecore_file/ecore_file.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/lib/ecore_file/ecore_file.c b/src/lib/ecore_file/ecore_file.c index 6e341ea640..f5c15b6e60 100644 --- a/src/lib/ecore_file/ecore_file.c +++ b/src/lib/ecore_file/ecore_file.c | |||
@@ -474,6 +474,7 @@ ecore_file_mv(const char *src, const char *dst) | |||
474 | if (is_reg) | 474 | if (is_reg) |
475 | { | 475 | { |
476 | char *dir; | 476 | char *dir; |
477 | Eina_Tmpstr *tmpstr = NULL; | ||
477 | 478 | ||
478 | dir = ecore_file_dir_get(dst); | 479 | dir = ecore_file_dir_get(dst); |
479 | // Since we can't directly rename, try to | 480 | // Since we can't directly rename, try to |
@@ -482,29 +483,40 @@ ecore_file_mv(const char *src, const char *dst) | |||
482 | snprintf(buf, sizeof(buf), "%s/.%s.tmp.XXXXXX", | 483 | snprintf(buf, sizeof(buf), "%s/.%s.tmp.XXXXXX", |
483 | dir, ecore_file_file_get(dst)); | 484 | dir, ecore_file_file_get(dst)); |
484 | free(dir); | 485 | free(dir); |
485 | fd = mkstemp(buf); | 486 | fd = eina_file_mkstemp(buf, &tmpstr); |
486 | if (fd < 0) goto FAIL; | 487 | if (fd < 0) goto FAIL; |
487 | close(fd); | 488 | close(fd); |
488 | 489 | ||
489 | // Copy to temp file | 490 | // Copy to temp file |
490 | if (!ecore_file_cp(src, buf)) | 491 | if (!ecore_file_cp(src, tmpstr)) |
491 | goto FAIL; | 492 | { |
493 | eina_tmpstr_del(tmpstr); | ||
494 | goto FAIL; | ||
495 | } | ||
492 | 496 | ||
493 | // Set file permissions of temp file to match src | 497 | // Set file permissions of temp file to match src |
494 | if (chmod(buf, mode) == -1) goto FAIL; | 498 | if (chmod(buf, mode) == -1) |
499 | { | ||
500 | eina_tmpstr_del(tmpstr); | ||
501 | goto FAIL; | ||
502 | } | ||
495 | 503 | ||
496 | // Try to atomically move temp file to dst | 504 | // Try to atomically move temp file to dst |
497 | if (rename(buf, dst)) | 505 | if (rename(tmpstr, dst)) |
498 | { | 506 | { |
499 | // If we still cannot atomically move | 507 | // If we still cannot atomically move |
500 | // do a normal copy and hope for the best. | 508 | // do a normal copy and hope for the best. |
501 | if (!ecore_file_cp(buf, dst)) | 509 | if (!ecore_file_cp(tmpstr, dst)) |
502 | goto FAIL; | 510 | { |
511 | eina_tmpstr_del(tmpstr); | ||
512 | goto FAIL; | ||
513 | } | ||
503 | } | 514 | } |
504 | 515 | ||
505 | // Delete temporary file and src | 516 | // Delete temporary file and src |
506 | ecore_file_unlink(buf); | 517 | ecore_file_unlink(tmpstr); |
507 | ecore_file_unlink(src); | 518 | ecore_file_unlink(src); |
519 | eina_tmpstr_del(tmpstr); | ||
508 | goto PASS; | 520 | goto PASS; |
509 | } | 521 | } |
510 | } | 522 | } |