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_FILE_COPY
I/O operation is about a specific file copy.
Definition: Eio_Legacy.h:109
@ EIO_DIR_COPY
I/O operation is about a specific directory copy.
Definition: Eio_Legacy.h:111
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
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
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
EIO_API int eio_init(void)
Initialize eio and all its required submodule.
Definition: eio_main.c:276
EIO_API int eio_shutdown(void)
Shutdown eio and all its submodule if possible.
Definition: eio_main.c:340
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
struct _Eio_File Eio_File
Generic asynchronous I/O reference.
Definition: Eio.h:73
Represents the current progress of the operation.
Definition: Eio_Legacy.h:176
float percent
Percent done for the I/O operation.
Definition: Eio_Legacy.h:181
long long current
Current step in the I/O operation.
Definition: Eio_Legacy.h:179
const char * dest
target of the I/O operation
Definition: Eio_Legacy.h:184
long long max
Number of total steps to complete this I/O.
Definition: Eio_Legacy.h:180
Eio_File_Op op
I/O type.
Definition: Eio_Legacy.h:177