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)
{
case EIO_FILE_COPY:
printf("[%s] %f%%\n", info->dest, info->percent);
break;
case EIO_DIR_COPY:
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");
ecore_main_loop_quit();
}
static void
_test_error_cb(int error, Eio_File *handler, void *data)
{
fprintf(stderr, "error: [%s]\n", strerror(error));
ecore_main_loop_quit();
}
int
main(int argc, char **argv)
{
Eio_File *cp;
if (argc != 3)
{
fprintf(stderr, "eio_cp source_file destination_file\n");
return -1;
}
ecore_init();
eio_init();
cp = eio_dir_copy(argv[1], argv[2],
_test_notify_cb,
_test_done_cb,
_test_error_cb,
NULL);
ecore_main_loop_begin();
eio_shutdown();
ecore_shutdown();
return 0;
}
EIO_FILE_COPY
@ EIO_FILE_COPY
I/O operation is about a specific file copy.
Definition Eio_Legacy.h:109
EIO_DIR_COPY
@ EIO_DIR_COPY
I/O operation is about a specific directory copy.
Definition Eio_Legacy.h:111
ecore_shutdown
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition ecore.c:371
ecore_init
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition ecore.c:230
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:1321
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition ecore_main.c:1311
eio_init
EIO_API int eio_init(void)
Initialize eio and all its required submodule.
Definition eio_main.c:276
eio_shutdown
EIO_API int eio_shutdown(void)
Shutdown eio and all its submodule if possible.
Definition eio_main.c:340
Eio_Progress
struct _Eio_Progress Eio_Progress
Progress information on a specific operation.
Definition Eio_Legacy.h:144
eio_dir_copy
EIO_API 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
struct _Eio_File Eio_File
Generic asynchronous I/O reference.
Definition Eio.h:73
_Eio_Progress::percent
float percent
Percent done for the I/O operation.
Definition Eio_Legacy.h:181
_Eio_Progress::current
long long current
Current step in the I/O operation.
Definition Eio_Legacy.h:179
_Eio_Progress::dest
const char * dest
target of the I/O operation
Definition Eio_Legacy.h:184
_Eio_Progress::max
long long max
Number of total steps to complete this I/O.
Definition Eio_Legacy.h:180
_Eio_Progress::op
Eio_File_Op op
I/O type.
Definition Eio_Legacy.h:177