summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bindings/luajit/eina/file.lua6
-rw-r--r--src/lib/eina/eina_file.c10
-rw-r--r--src/lib/eina/eina_file_win32.c24
-rw-r--r--src/tests/eina/eina_test_file.c41
4 files changed, 81 insertions, 0 deletions
diff --git a/src/bindings/luajit/eina/file.lua b/src/bindings/luajit/eina/file.lua
index d776047..675b810 100644
--- a/src/bindings/luajit/eina/file.lua
+++ b/src/bindings/luajit/eina/file.lua
@@ -97,6 +97,7 @@ ffi.cdef [[
97 Eina_File_Copy_Flags flags, Eina_File_Copy_Progress cb, 97 Eina_File_Copy_Flags flags, Eina_File_Copy_Progress cb,
98 const void *cb_data); 98 const void *cb_data);
99 Eina_File *eina_file_open(const char *name, Eina_Bool shared); 99 Eina_File *eina_file_open(const char *name, Eina_Bool shared);
100 Eina_Bool eina_file_unlink(const char *pathname);
100 Eina_File *eina_file_virtualize(const char *virtual_name, 101 Eina_File *eina_file_virtualize(const char *virtual_name,
101 const void *data, unsigned long long length, Eina_Bool copy); 102 const void *data, unsigned long long length, Eina_Bool copy);
102 Eina_Bool eina_file_virtual(Eina_File *file); 103 Eina_Bool eina_file_virtual(Eina_File *file);
@@ -315,6 +316,11 @@ M.File = ffi.metatype("Eina_File", {
315 open = function(name, shared) 316 open = function(name, shared)
316 return eina.eina_file_open(name, shared) 317 return eina.eina_file_open(name, shared)
317 end, 318 end,
319
320 unlink = function(self)
321 return eina.eina_file_unlink(pathname)
322 end,
323
318 virtualize = function(vname, data, length, copy) 324 virtualize = function(vname, data, length, copy)
319 return eina.eina_file_virtualize(vname, data, length, 325 return eina.eina_file_virtualize(vname, data, length,
320 copy or false) 326 copy or false)
diff --git a/src/lib/eina/eina_file.c b/src/lib/eina/eina_file.c
index cb29f28..c378ea5 100644
--- a/src/lib/eina/eina_file.c
+++ b/src/lib/eina/eina_file.c
@@ -898,6 +898,16 @@ eina_file_refresh(Eina_File *file)
898 return r; 898 return r;
899} 899}
900 900
901EAPI Eina_Bool
902eina_file_unlink(const char *pathname)
903{
904 if ( unlink(pathname) < 0)
905 {
906 return EINA_FALSE;
907 }
908 return EINA_TRUE;
909}
910
901EAPI void * 911EAPI void *
902eina_file_map_all(Eina_File *file, Eina_File_Populate rule) 912eina_file_map_all(Eina_File *file, Eina_File_Populate rule)
903{ 913{
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index 54b5d90..fe83c67 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -821,6 +821,30 @@ eina_file_open(const char *path, Eina_Bool shared)
821 return NULL; 821 return NULL;
822} 822}
823 823
824EAPI Eina_Bool
825eina_file_unlink(const char *pathname)
826{
827 char *unlink_path = eina_file_path_sanitize(pathname);
828 Eina_File *file = eina_hash_find(_eina_file_cache, unlink_path);
829
830 if (file)
831 {
832 if (file->handle != INVALID_HANDLE_VALUE)
833 {
834 CloseHandle(file->handle);
835 file->handle = INVALID_HANDLE_VALUE;
836 }
837 }
838
839 if ( unlink(unlink_path) < 0)
840 {
841 return EINA_FALSE;
842 }
843
844 return EINA_TRUE;
845}
846
847
824EAPI Eina_Iterator *eina_file_xattr_get(Eina_File *file EINA_UNUSED) 848EAPI Eina_Iterator *eina_file_xattr_get(Eina_File *file EINA_UNUSED)
825{ 849{
826 return NULL; 850 return NULL;
diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c
index c82f600..e3c60b6 100644
--- a/src/tests/eina/eina_test_file.c
+++ b/src/tests/eina/eina_test_file.c
@@ -824,6 +824,45 @@ START_TEST(eina_test_file_mktemp)
824} 824}
825END_TEST 825END_TEST
826 826
827int create_file_not_empty(const char *file_name, Eina_Tmpstr **test_file_path, Eina_Bool close_file)
828{
829 const char *data = "abcdefghijklmnopqrstuvwxyz";
830 int data_size = strlen(data);
831 int wr_size;
832 int fd = eina_file_mkstemp(file_name, test_file_path);
833 fail_if(fd <= 0);
834 wr_size = write(fd, data, data_size);
835 if(close_file == EINA_TRUE)
836 {
837 close(fd);
838 fd = 0;
839 }
840 fail_if(wr_size != data_size);
841 return fd;
842}
843
844START_TEST(eina_test_file_unlink)
845{
846 int fd;
847 Eina_File *file;
848 Eina_Tmpstr *test_file_path;
849 const char *tmpfile = "eina_file_test_XXXXXX";
850
851 eina_init();
852
853 /*If file was not opened as 'eina'*/
854 fd = create_file_not_empty(tmpfile, &test_file_path, EINA_TRUE);
855 fail_if( !eina_file_unlink(test_file_path) );
856
857 /*If file was opened as 'eina'*/
858 fd = create_file_not_empty(tmpfile, &test_file_path, EINA_TRUE);
859 fail_if( !eina_file_open(test_file_path, EINA_FALSE) );
860 fail_if( !eina_file_unlink(test_file_path) );
861
862 eina_shutdown();
863}
864END_TEST
865
827void 866void
828eina_test_file(TCase *tc) 867eina_test_file(TCase *tc)
829{ 868{
@@ -840,4 +879,6 @@ eina_test_file(TCase *tc)
840 tcase_add_test(tc, eina_test_file_copy); 879 tcase_add_test(tc, eina_test_file_copy);
841 tcase_add_test(tc, eina_test_file_statat); 880 tcase_add_test(tc, eina_test_file_statat);
842 tcase_add_test(tc, eina_test_file_mktemp); 881 tcase_add_test(tc, eina_test_file_mktemp);
882 tcase_add_test(tc, eina_test_file_unlink);
883
843} 884}