eio_dir_copy() tutorial

To use eio_dir_copy(), you basically need the source and destination files (or directories), and set three callbacks:

  • The notification callback, which allows you to know if a file or a directory is copied, and the progress of the copy.
  • The end callback, which is called when the copy is finished.
  • The error callback, which is called if an error occurred. You can then retrieve the error type as an errno error.
Warning
It is the user's duty to provide the "right target". It means that copying to '.' will copy the content directly inside '.' and not in a subdirectory.

Here is a simple example:

#include <Ecore.h>
#include <Eio.h>
static void
_test_notify_cb(void *data, Eio_File *handler, const Eio_Progress *info)
{
switch (info->op)
{
printf("[%s] %f%%\n", info->dest, info->percent);
break;
printf("global [%li/%li] %f%%\n", info->current, info->max, info->percent);
break;
}
}
static void
_test_done_cb(void *data, Eio_File *handler)
{
printf("copy done\n");
}
static void
_test_error_cb(int error, Eio_File *handler, void *data)
{
fprintf(stderr, "error: [%s]\n", strerror(error));
}
int
main(int argc, char **argv)
{
Eio_File *cp;
if (argc != 3)
{
fprintf(stderr, "eio_cp source_file destination_file\n");
return -1;
}
cp = eio_dir_copy(argv[1], argv[2],
_test_notify_cb,
_test_done_cb,
_test_error_cb,
NULL);
return 0;
}
_Eio_Progress
Represents the current progress of the operation.
Definition: Eio_Legacy.h:176
_Eio_Progress::percent
float percent
Percent done for the I/O operation.
Definition: Eio_Legacy.h:181
ecore_main_loop_quit
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition: ecore_main.c:1308
_Eio_Progress::dest
const char * dest
target of the I/O operation
Definition: Eio_Legacy.h:184
EIO_DIR_COPY
@ EIO_DIR_COPY
I/O operation is about a specific directory copy.
Definition: Eio_Legacy.h:111
eio_shutdown
int eio_shutdown(void)
Shutdown eio and all its submodule if possible.
Definition: eio_main.c:340
_Eio_Progress::current
long long current
Current step in the I/O operation.
Definition: Eio_Legacy.h:179
eio_dir_copy
Eio_File * eio_dir_copy(const char *source, const char *dest, Eio_Filter_Direct_Cb filter_cb, Eio_Progress_Cb progress_cb, Eio_Done_Cb done_cb, Eio_Error_Cb error_cb, const void *data)
Copy a directory and its content asynchronously.
Definition: eio_dir.c:849
EIO_FILE_COPY
@ EIO_FILE_COPY
I/O operation is about a specific file copy.
Definition: Eio_Legacy.h:109
eio_init
int eio_init(void)
Initialize eio and all its required submodule.
Definition: eio_main.c:276
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1298
_Eio_Progress::op
Eio_File_Op op
I/O type.
Definition: Eio_Legacy.h:177
ecore_shutdown
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:366
_Eio_Progress::max
long long max
Number of total steps to complete this I/O.
Definition: Eio_Legacy.h:180
Eio_File
struct _Eio_File Eio_File
Generic asynchronous I/O reference.
Definition: Eio.h:72
ecore_init
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:225