formatting

SVN revision: 72392
This commit is contained in:
Mike Blumenkrantz 2012-06-18 12:49:07 +00:00
parent 3d5b67d428
commit bd73abaffa
1 changed files with 368 additions and 362 deletions

View File

@ -1,7 +1,7 @@
#include "config.h"
#ifndef _FILE_OFFSET_BITS
# define _FILE_OFFSET_BITS 64
# define _FILE_OFFSET_BITS 64
#endif
#ifdef HAVE_ALLOCA_H
@ -18,7 +18,7 @@
# ifdef __cplusplus
extern "C"
# endif
void *alloca (size_t);
void *alloca(size_t);
#endif
#include <unistd.h>
@ -43,51 +43,51 @@ void *alloca (size_t);
#undef E_TYPEDEFS
#include "e_fm_op.h"
#define READBUFSIZE 65536
#define COPYBUFSIZE 16384
#define READBUFSIZE 65536
#define COPYBUFSIZE 16384
#define REMOVECHUNKSIZE 4096
#define FREE(p) do { if (p) {free((void *)p); p = NULL;} } while (0)
#define FREE(p) do { if (p) {free((void *)p); p = NULL; } } while (0)
#define LG(fmt, args...) {\
FILE *f = fopen("log", "a"); \
if (f) fprintf(f, fmt, ##args); \
if (f) fclose(f); \
#define LG(fmt, args ...) { \
FILE *f = fopen("log", "a"); \
if (f) fprintf(f, fmt, ##args); \
if (f) fclose(f); \
}
typedef struct _E_Fm_Op_Task E_Fm_Op_Task;
typedef struct _E_Fm_Op_Task E_Fm_Op_Task;
typedef struct _E_Fm_Op_Copy_Data E_Fm_Op_Copy_Data;
static E_Fm_Op_Task *_e_fm_op_task_new();
static void _e_fm_op_task_free(void *t);
static void _e_fm_op_task_free(void *t);
static void _e_fm_op_remove_link_task(E_Fm_Op_Task *task);
static Eina_Bool _e_fm_op_stdin_data(void *data, Ecore_Fd_Handler * fd_handler);
static void _e_fm_op_set_up_idlers();
static void _e_fm_op_delete_idler(int *mark);
static int _e_fm_op_idler_handle_error(int *mark, Eina_List **queue, Eina_List **node, E_Fm_Op_Task *task);
static void _e_fm_op_remove_link_task(E_Fm_Op_Task *task);
static Eina_Bool _e_fm_op_stdin_data(void *data, Ecore_Fd_Handler *fd_handler);
static void _e_fm_op_set_up_idlers();
static void _e_fm_op_delete_idler(int *mark);
static int _e_fm_op_idler_handle_error(int *mark, Eina_List **queue, Eina_List **node, E_Fm_Op_Task *task);
static Eina_Bool _e_fm_op_work_idler(void *data);
static Eina_Bool _e_fm_op_scan_idler(void *data);
static Eina_Bool _e_fm_op_work_idler(void *data);
static Eina_Bool _e_fm_op_scan_idler(void *data);
static void _e_fm_op_send_error(E_Fm_Op_Task * task, E_Fm_Op_Type type, const char *fmt, ...);
static void _e_fm_op_rollback(E_Fm_Op_Task * task);
static void _e_fm_op_update_progress_report_simple(int percent, const char *src, const char *dst);
static void _e_fm_op_update_progress(E_Fm_Op_Task *task, off_t _plus_e_fm_op_done, off_t _plus_e_fm_op_total);
static void _e_fm_op_copy_stat_info(E_Fm_Op_Task *task);
static int _e_fm_op_handle_overwrite(E_Fm_Op_Task *task);
static void _e_fm_op_send_error(E_Fm_Op_Task *task, E_Fm_Op_Type type, const char *fmt, ...);
static void _e_fm_op_rollback(E_Fm_Op_Task *task);
static void _e_fm_op_update_progress_report_simple(int percent, const char *src, const char *dst);
static void _e_fm_op_update_progress(E_Fm_Op_Task *task, off_t _plus_e_fm_op_done, off_t _plus_e_fm_op_total);
static void _e_fm_op_copy_stat_info(E_Fm_Op_Task *task);
static int _e_fm_op_handle_overwrite(E_Fm_Op_Task *task);
static int _e_fm_op_copy_dir(E_Fm_Op_Task * task);
static int _e_fm_op_copy_link(E_Fm_Op_Task *task);
static int _e_fm_op_copy_fifo(E_Fm_Op_Task *task);
static int _e_fm_op_open_files(E_Fm_Op_Task *task);
static int _e_fm_op_copy_chunk(E_Fm_Op_Task *task);
static int _e_fm_op_copy_dir(E_Fm_Op_Task *task);
static int _e_fm_op_copy_link(E_Fm_Op_Task *task);
static int _e_fm_op_copy_fifo(E_Fm_Op_Task *task);
static int _e_fm_op_open_files(E_Fm_Op_Task *task);
static int _e_fm_op_copy_chunk(E_Fm_Op_Task *task);
static int _e_fm_op_copy_atom(E_Fm_Op_Task * task);
static int _e_fm_op_scan_atom(E_Fm_Op_Task * task);
static int _e_fm_op_copy_stat_info_atom(E_Fm_Op_Task * task);
static int _e_fm_op_symlink_atom(E_Fm_Op_Task * task);
static int _e_fm_op_remove_atom(E_Fm_Op_Task * task);
static int _e_fm_op_copy_atom(E_Fm_Op_Task *task);
static int _e_fm_op_scan_atom(E_Fm_Op_Task *task);
static int _e_fm_op_copy_stat_info_atom(E_Fm_Op_Task *task);
static int _e_fm_op_symlink_atom(E_Fm_Op_Task *task);
static int _e_fm_op_remove_atom(E_Fm_Op_Task *task);
Ecore_Fd_Handler *_e_fm_op_stdin_handler = NULL;
@ -100,7 +100,7 @@ off_t _e_fm_op_done, _e_fm_op_total; /* Type long long should be 64 bits wide ev
Well, we'll be multipling _e_fm_op_done by 100, but
still, it is big enough. */
int _e_fm_op_abort = 0; /* Abort mark. */
int _e_fm_op_abort = 0; /* Abort mark. */
int _e_fm_op_scan_error = 0;
int _e_fm_op_work_error = 0;
int _e_fm_op_overwrite = 0;
@ -123,17 +123,17 @@ struct _E_Fm_Op_Task
struct
{
const char *name;
size_t done;
size_t done;
} dst;
int started, finished;
int started, finished;
void *data;
void *data;
E_Fm_Op_Type type;
E_Fm_Op_Type overwrite;
Eina_List *link;
Eina_List *link;
};
struct _E_Fm_Op_Copy_Data
@ -163,152 +163,155 @@ main(int argc, char **argv)
i = 2;
if (!strcmp(argv[1], "cp")) type = E_FM_OP_COPY;
else if (!strcmp(argv[1], "mv")) type = E_FM_OP_MOVE;
else if (!strcmp(argv[1], "rm")) type = E_FM_OP_REMOVE;
else if (!strcmp(argv[1], "lns")) type = E_FM_OP_SYMLINK;
else if (!strcmp(argv[1], "mv"))
type = E_FM_OP_MOVE;
else if (!strcmp(argv[1], "rm"))
type = E_FM_OP_REMOVE;
else if (!strcmp(argv[1], "lns"))
type = E_FM_OP_SYMLINK;
else return 0;
if ((type == E_FM_OP_COPY) ||
(type == E_FM_OP_SYMLINK) ||
(type == E_FM_OP_MOVE))
{
if (argc < 4) goto quit;
if (argc < 4) goto quit;
if (type == E_FM_OP_MOVE)
{
_e_fm_op_work_queue = eina_list_append(_e_fm_op_work_queue, NULL);
_e_fm_op_separator = _e_fm_op_work_queue;
}
if (type == E_FM_OP_MOVE)
{
_e_fm_op_work_queue = eina_list_append(_e_fm_op_work_queue, NULL);
_e_fm_op_separator = _e_fm_op_work_queue;
}
if ((argc >= 4) && (ecore_file_is_dir(argv[last])))
{
char buf[PATH_MAX];
char *p2, *p3;
int p2_len, last_len, done, total;
if ((argc >= 4) && (ecore_file_is_dir(argv[last])))
{
char buf[PATH_MAX];
char *p2, *p3;
int p2_len, last_len, done, total;
p2 = ecore_file_realpath(argv[last]);
if (!p2) goto quit;
p2_len = strlen(p2);
p2 = ecore_file_realpath(argv[last]);
if (!p2) goto quit;
p2_len = strlen(p2);
last_len = strlen(argv[last]);
if ((last_len < 1) || (last_len + 2 >= PATH_MAX))
{
free(p2);
goto quit;
}
memcpy(buf, argv[last], last_len);
if (buf[last_len - 1] != '/')
{
buf[last_len] = '/';
last_len++;
}
last_len = strlen(argv[last]);
if ((last_len < 1) || (last_len + 2 >= PATH_MAX))
{
free(p2);
goto quit;
}
memcpy(buf, argv[last], last_len);
if (buf[last_len - 1] != '/')
{
buf[last_len] = '/';
last_len++;
}
p3 = buf + last_len;
p3 = buf + last_len;
done = 0;
total = last - 2;
done = 0;
total = last - 2;
for (; i < last; i++)
{
char *p = ecore_file_realpath(argv[i]);
const char *name;
int name_len;
for (; i < last; i++)
{
char *p = ecore_file_realpath(argv[i]);
const char *name;
int name_len;
if (!p) continue;
if (!p) continue;
/* Don't move a dir into itself */
if (ecore_file_is_dir(p) &&
(strncmp(p, p2, PATH_MAX) == 0) &&
((p[p2_len] == '/') || (p[p2_len] == '\0')))
goto skip_arg;
/* Don't move a dir into itself */
if (ecore_file_is_dir(p) &&
(strncmp(p, p2, PATH_MAX) == 0) &&
((p[p2_len] == '/') || (p[p2_len] == '\0')))
goto skip_arg;
name = ecore_file_file_get(p);
if (!name) goto skip_arg;
name_len = strlen(name);
if (p2_len + name_len >= PATH_MAX) goto skip_arg;
memcpy(p3, name, name_len + 1);
name = ecore_file_file_get(p);
if (!name) goto skip_arg;
name_len = strlen(name);
if (p2_len + name_len >= PATH_MAX) goto skip_arg;
memcpy(p3, name, name_len + 1);
if ((type == E_FM_OP_MOVE) &&
(rename(argv[i], buf) == 0))
{
done++;
_e_fm_op_update_progress_report_simple
(done * 100 / total, argv[i], buf);
}
else if ((type == E_FM_OP_SYMLINK) &&
(symlink(argv[i], buf) == 0))
{
done++;
_e_fm_op_update_progress_report_simple
(done * 100 / total, argv[i], buf);
}
else
{
E_Fm_Op_Task *task;
if ((type == E_FM_OP_MOVE) &&
(rename(argv[i], buf) == 0))
{
done++;
_e_fm_op_update_progress_report_simple
(done * 100 / total, argv[i], buf);
}
else if ((type == E_FM_OP_SYMLINK) &&
(symlink(argv[i], buf) == 0))
{
done++;
_e_fm_op_update_progress_report_simple
(done * 100 / total, argv[i], buf);
}
else
{
E_Fm_Op_Task *task;
task = _e_fm_op_task_new();
task->type = type;
task->src.name = eina_stringshare_add(argv[i]);
task->dst.name = eina_stringshare_add(buf);
task = _e_fm_op_task_new();
task->type = type;
task->src.name = eina_stringshare_add(argv[i]);
task->dst.name = eina_stringshare_add(buf);
_e_fm_op_scan_queue =
eina_list_append(_e_fm_op_scan_queue, task);
}
_e_fm_op_scan_queue =
eina_list_append(_e_fm_op_scan_queue, task);
}
skip_arg:
free(p);
}
skip_arg:
free(p);
}
free(p2);
}
else if (argc == 4)
{
char *p, *p2;
free(p2);
}
else if (argc == 4)
{
char *p, *p2;
p = ecore_file_realpath(argv[2]);
p2 = ecore_file_realpath(argv[3]);
p = ecore_file_realpath(argv[2]);
p2 = ecore_file_realpath(argv[3]);
/* Don't move a file on top of itself. */
i = (strcmp(p, p2) == 0);
free(p);
free(p2);
if (i) goto quit;
/* Don't move a file on top of itself. */
i = (strcmp(p, p2) == 0);
free(p);
free(p2);
if (i) goto quit;
/* Try a rename */
if ((type == E_FM_OP_MOVE) && (rename(argv[2], argv[3]) == 0))
{
_e_fm_op_update_progress_report_simple(100, argv[2], argv[3]);
goto quit;
}
else if ((type == E_FM_OP_SYMLINK) &&
(symlink(argv[2], argv[3]) == 0))
{
_e_fm_op_update_progress_report_simple(100, argv[2], argv[3]);
goto quit;
}
else
{
E_Fm_Op_Task *task;
/* Try a rename */
if ((type == E_FM_OP_MOVE) && (rename(argv[2], argv[3]) == 0))
{
_e_fm_op_update_progress_report_simple(100, argv[2], argv[3]);
goto quit;
}
else if ((type == E_FM_OP_SYMLINK) &&
(symlink(argv[2], argv[3]) == 0))
{
_e_fm_op_update_progress_report_simple(100, argv[2], argv[3]);
goto quit;
}
else
{
E_Fm_Op_Task *task;
/* If that doesn't work, setup a copy and delete operation.
It's not atomic, but it's the best we can do. */
task = _e_fm_op_task_new();
task->type = type;
task->src.name = eina_stringshare_add(argv[2]);
task->dst.name = eina_stringshare_add(argv[3]);
_e_fm_op_scan_queue = eina_list_append(_e_fm_op_scan_queue, task);
}
}
else
goto quit;
/* If that doesn't work, setup a copy and delete operation.
It's not atomic, but it's the best we can do. */
task = _e_fm_op_task_new();
task->type = type;
task->src.name = eina_stringshare_add(argv[2]);
task->dst.name = eina_stringshare_add(argv[3]);
_e_fm_op_scan_queue = eina_list_append(_e_fm_op_scan_queue, task);
}
}
else
goto quit;
}
else if (type == E_FM_OP_REMOVE)
{
if (argc < 3) return 0;
if (argc < 3) return 0;
while (i <= last)
{
E_Fm_Op_Task *task;
E_Fm_Op_Task *task;
task = _e_fm_op_task_new();
task->type = type;
@ -374,8 +377,8 @@ _e_fm_op_task_free(void *t)
{
if (data->from) fclose(data->from);
if (data->to) fclose(data->to);
}
FREE(task->data);
}
FREE(task->data);
}
FREE(task);
}
@ -414,7 +417,7 @@ _e_fm_op_remove_link_task(E_Fm_Op_Task *task)
* did not actually read enough data.
*/
static Eina_Bool
_e_fm_op_stdin_data(void *data __UNUSED__, Ecore_Fd_Handler * fd_handler)
_e_fm_op_stdin_data(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler)
{
int fd;
static char *buf = NULL;
@ -435,12 +438,12 @@ _e_fm_op_stdin_data(void *data __UNUSED__, Ecore_Fd_Handler * fd_handler)
if (num == 0)
{
E_FM_OP_DEBUG("STDIN was closed. Abort. \n");
_e_fm_op_abort = 1;
_e_fm_op_abort = 1;
}
else if (num < 0)
{
E_FM_OP_DEBUG("Error while reading from STDIN: read returned -1. (%s) Abort. \n", strerror(errno));
_e_fm_op_abort = 1;
_e_fm_op_abort = 1;
}
else
{
@ -449,31 +452,31 @@ _e_fm_op_stdin_data(void *data __UNUSED__, Ecore_Fd_Handler * fd_handler)
buf = _e_fm_op_stdin_buffer;
begin = _e_fm_op_stdin_buffer;
while (length >= ((int)(3 * sizeof(int))))
{
while (length >= ((int)(3 * sizeof(int))))
{
begin = buf;
/* Check magic. */
if (*((int *)buf) != E_FM_OP_MAGIC)
/* Check magic. */
if (*((int *)buf) != E_FM_OP_MAGIC)
{
E_FM_OP_DEBUG("Error while reading from STDIN: magic is not correct!\n");
break;
}
buf += sizeof(int);
buf += sizeof(int);
/* Read indentifying data. */
memcpy(&identity, buf, sizeof(int));
buf += sizeof(int);
memcpy(&identity, buf, sizeof(int));
buf += sizeof(int);
/* Read message length. */
memcpy(&msize, buf, sizeof(int));
buf += sizeof(int);
/* Read message length. */
memcpy(&msize, buf, sizeof(int));
buf += sizeof(int);
if ((length - 3 * (int)sizeof(int)) < msize)
{
/* There is not enough data to read the whole message. */
if ((length - 3 * (int)sizeof(int)) < msize)
{
/* There is not enough data to read the whole message. */
break;
}
}
length -= (3 * sizeof(int));
@ -481,29 +484,31 @@ _e_fm_op_stdin_data(void *data __UNUSED__, Ecore_Fd_Handler * fd_handler)
* but currently commands here do not have any data.
* msize is always 0.
*/
switch (identity)
{
case E_FM_OP_ABORT:
switch (identity)
{
case E_FM_OP_ABORT:
_e_fm_op_abort = 1;
E_FM_OP_DEBUG("Aborted.\n");
break;
case E_FM_OP_ERROR_RESPONSE_ABORT:
case E_FM_OP_ERROR_RESPONSE_IGNORE_THIS:
case E_FM_OP_ERROR_RESPONSE_IGNORE_ALL:
case E_FM_OP_ERROR_RESPONSE_RETRY:
_e_fm_op_error_response = identity;
case E_FM_OP_ERROR_RESPONSE_ABORT:
case E_FM_OP_ERROR_RESPONSE_IGNORE_THIS:
case E_FM_OP_ERROR_RESPONSE_IGNORE_ALL:
case E_FM_OP_ERROR_RESPONSE_RETRY:
_e_fm_op_error_response = identity;
_e_fm_op_set_up_idlers();
break;
case E_FM_OP_OVERWRITE_RESPONSE_NO:
case E_FM_OP_OVERWRITE_RESPONSE_NO_ALL:
case E_FM_OP_OVERWRITE_RESPONSE_YES:
case E_FM_OP_OVERWRITE_RESPONSE_YES_ALL:
case E_FM_OP_OVERWRITE_RESPONSE_NO:
case E_FM_OP_OVERWRITE_RESPONSE_NO_ALL:
case E_FM_OP_OVERWRITE_RESPONSE_YES:
case E_FM_OP_OVERWRITE_RESPONSE_YES_ALL:
_e_fm_op_overwrite_response = identity;
_e_fm_op_set_up_idlers();
E_FM_OP_DEBUG("Overwrite response set.\n");
break;
}
}
}
}
if (length > 0) memmove(_e_fm_op_stdin_buffer, begin, length);
buf = _e_fm_op_stdin_buffer + length;
}
@ -520,25 +525,25 @@ _e_fm_op_set_up_idlers()
_e_fm_op_work_idler_p = ecore_idler_add(_e_fm_op_work_idler, NULL);
}
#define _E_FM_OP_ERROR_SEND_SCAN(_task, _e_fm_op_error_type, _fmt, ...)\
do\
{\
int _errno = errno;\
_e_fm_op_scan_error = 1;\
_e_fm_op_send_error(_task, _e_fm_op_error_type, _fmt, __VA_ARGS__, strerror(_errno));\
return 1;\
}\
while (0)
#define _E_FM_OP_ERROR_SEND_SCAN(_task, _e_fm_op_error_type, _fmt, ...) \
do \
{ \
int _errno = errno; \
_e_fm_op_scan_error = 1; \
_e_fm_op_send_error(_task, _e_fm_op_error_type, _fmt, __VA_ARGS__, strerror(_errno)); \
return 1; \
} \
while (0)
#define _E_FM_OP_ERROR_SEND_WORK(_task, _e_fm_op_error_type, _fmt, ...)\
do\
{\
int _errno = errno;\
_e_fm_op_work_error = 1;\
_e_fm_op_send_error(_task, _e_fm_op_error_type, _fmt, __VA_ARGS__, strerror(_errno));\
return 1;\
}\
while (0)
#define _E_FM_OP_ERROR_SEND_WORK(_task, _e_fm_op_error_type, _fmt, ...) \
do \
{ \
int _errno = errno; \
_e_fm_op_work_error = 1; \
_e_fm_op_send_error(_task, _e_fm_op_error_type, _fmt, __VA_ARGS__, strerror(_errno)); \
return 1; \
} \
while (0)
static void
_e_fm_op_delete_idler(int *mark)
@ -627,7 +632,7 @@ _e_fm_op_idler_handle_error(int *mark, Eina_List **queue, Eina_List **node, E_Fm
}
}
}
else if (( _e_fm_op_work_error) || (_e_fm_op_scan_error))
else if ((_e_fm_op_work_error) || (_e_fm_op_scan_error))
return 1;
return 0;
}
@ -706,16 +711,16 @@ _e_fm_op_work_idler(void *data __UNUSED__)
if (task->finished)
{
_e_fm_op_work_queue = eina_list_remove_list(_e_fm_op_work_queue, node);
_e_fm_op_task_free(task);
node = NULL;
_e_fm_op_work_queue = eina_list_remove_list(_e_fm_op_work_queue, node);
_e_fm_op_task_free(task);
node = NULL;
}
if (_e_fm_op_abort)
{
/* So, _atom did what it whats in case of abort. Now to idler. */
ecore_main_loop_quit();
return ECORE_CALLBACK_CANCEL;
/* So, _atom did what it whats in case of abort. Now to idler. */
ecore_main_loop_quit();
return ECORE_CALLBACK_CANCEL;
}
return ECORE_CALLBACK_RENEW;
@ -744,8 +749,8 @@ _e_fm_op_scan_idler(void *data __UNUSED__)
if (!task)
{
_e_fm_op_scan_idler_p = NULL;
return ECORE_CALLBACK_CANCEL;
_e_fm_op_scan_idler_p = NULL;
return ECORE_CALLBACK_CANCEL;
}
if (_e_fm_op_idler_handle_error(&_e_fm_op_scan_error, &_e_fm_op_scan_queue, &node, task))
@ -753,9 +758,9 @@ _e_fm_op_scan_idler(void *data __UNUSED__)
if (_e_fm_op_abort)
{
/* We're marked for abortion. */
ecore_main_loop_quit();
return ECORE_CALLBACK_CANCEL;
/* We're marked for abortion. */
ecore_main_loop_quit();
return ECORE_CALLBACK_CANCEL;
}
if (task->type == E_FM_OP_COPY_STAT_INFO)
@ -771,13 +776,13 @@ _e_fm_op_scan_idler(void *data __UNUSED__)
}
else if (!dir && !task->started)
{
if (lstat(task->src.name, &(task->src.st)) < 0)
if (lstat(task->src.name, &(task->src.st)) < 0)
_E_FM_OP_ERROR_SEND_SCAN(task, E_FM_OP_ERROR,
"Cannot lstat '%s': %s.", task->src.name);
if (S_ISDIR(task->src.st.st_mode))
{
/* If it's a dir, then look through it and add a task for each. */
if (S_ISDIR(task->src.st.st_mode))
{
/* If it's a dir, then look through it and add a task for each. */
dir = eina_file_direct_ls(task->src.name);
if (!dir)
@ -798,7 +803,7 @@ _e_fm_op_scan_idler(void *data __UNUSED__)
{
Eina_File_Direct_Info *info;
if (!eina_iterator_next(dir, (void**) &info))
if (!eina_iterator_next(dir, (void **)&info))
{
ntask = _e_fm_op_task_new();
ntask->type = E_FM_OP_COPY_STAT_INFO;
@ -812,10 +817,10 @@ _e_fm_op_scan_idler(void *data __UNUSED__)
if (task->type == E_FM_OP_REMOVE)
_e_fm_op_scan_queue =
eina_list_prepend(_e_fm_op_scan_queue, ntask);
eina_list_prepend(_e_fm_op_scan_queue, ntask);
else
_e_fm_op_scan_queue =
eina_list_append(_e_fm_op_scan_queue, ntask);
eina_list_append(_e_fm_op_scan_queue, ntask);
task->started = 1;
eina_iterator_free(dir);
@ -843,8 +848,8 @@ _e_fm_op_scan_idler(void *data __UNUSED__)
}
else
{
_e_fm_op_scan_atom(task);
if (task->finished)
_e_fm_op_scan_atom(task);
if (task->finished)
{
_e_fm_op_scan_queue =
eina_list_remove_list(_e_fm_op_scan_queue, node);
@ -874,7 +879,7 @@ _e_fm_op_send_error(E_Fm_Op_Task *task __UNUSED__, E_Fm_Op_Type type, const char
if (_e_fm_op_error_response == E_FM_OP_ERROR_RESPONSE_IGNORE_ALL)
{
/* Do nothing. */
/* Do nothing. */
}
else
{
@ -890,7 +895,7 @@ _e_fm_op_send_error(E_Fm_Op_Task *task __UNUSED__, E_Fm_Op_Type type, const char
ret = write(STDOUT_FILENO, buf, (3 * sizeof(int)) + len + 1);
E_FM_OP_DEBUG("%s", str);
E_FM_OP_DEBUG(" Error sent.\n");
E_FM_OP_DEBUG(" Error sent.\n");
}
va_end(ap);
@ -906,21 +911,21 @@ _e_fm_op_rollback(E_Fm_Op_Task *task)
if (task->type == E_FM_OP_COPY)
{
data = task->data;
if (data)
{
if (data->from)
{
fclose(data->from);
data->from = NULL;
}
if (data->to)
{
fclose(data->to);
data->to = NULL;
}
}
FREE(task->data);
data = task->data;
if (data)
{
if (data->from)
{
fclose(data->from);
data->from = NULL;
}
if (data->to)
{
fclose(data->to);
data->to = NULL;
}
}
FREE(task->data);
}
if (task->type == E_FM_OP_COPY)
@ -1008,31 +1013,31 @@ _e_fm_op_update_progress(E_Fm_Op_Task *task, off_t _plus_e_fm_op_done, off_t _pl
if (_e_fm_op_total != 0)
{
/* % 101 is for the case when somehow work queue works faster
than scan queue. _e_fm_op_done * 100 should not cause arithmetic
overflow, since long long can hold really big values. */
percent = _e_fm_op_done * 100 / _e_fm_op_total % 101;
than scan queue. _e_fm_op_done * 100 should not cause arithmetic
overflow, since long long can hold really big values. */
percent = _e_fm_op_done * 100 / _e_fm_op_total % 101;
eta = peta;
if (!s_time) s_time = ecore_time_get();
/* Update ETA once a second */
if ((_e_fm_op_done) && (ecore_time_get() - c_time > 1.0 ))
if ((_e_fm_op_done) && (ecore_time_get() - c_time > 1.0))
{
c_time = ecore_time_get();
eta = (c_time - s_time) * (_e_fm_op_total - _e_fm_op_done) / _e_fm_op_done;
eta = (int) (eta + 0.5);
eta = (int)(eta + 0.5);
}
if ((percent != ppercent) || (eta != peta) || ((task) && (task != ptask)))
{
ppercent = percent;
if ((percent != ppercent) || (eta != peta) || ((task) && (task != ptask)))
{
ppercent = percent;
peta = eta;
ptask = task;
_e_fm_op_update_progress_report(percent, eta, c_time - s_time,
_e_fm_op_done, _e_fm_op_total,
task->src.name, task->dst.name);
}
_e_fm_op_update_progress_report(percent, eta, c_time - s_time,
_e_fm_op_done, _e_fm_op_total,
task->src.name, task->dst.name);
}
}
}
@ -1110,7 +1115,7 @@ _e_fm_op_handle_overwrite(E_Fm_Op_Task *task)
}
static int
_e_fm_op_copy_dir(E_Fm_Op_Task * task)
_e_fm_op_copy_dir(E_Fm_Op_Task *task)
{
struct stat st;
@ -1313,7 +1318,7 @@ _e_fm_op_copy_chunk(E_Fm_Op_Task *task)
* Return value does not matter. It's there only to _E_FM_OP_ERROR_SEND macro to work correctly. (Well, it works fine, just don't want GCC to produce a warning.)
*/
static int
_e_fm_op_copy_atom(E_Fm_Op_Task * task)
_e_fm_op_copy_atom(E_Fm_Op_Task *task)
{
E_Fm_Op_Copy_Data *data;
@ -1321,35 +1326,35 @@ _e_fm_op_copy_atom(E_Fm_Op_Task * task)
data = task->data;
if ((!data) || (!data->to) || (!data->from)) /* Did not touch the files yet. */
if ((!data) || (!data->to) || (!data->from)) /* Did not touch the files yet. */
{
E_FM_OP_DEBUG("Copy: %s --> %s\n", task->src.name, task->dst.name);
if (_e_fm_op_abort)
{
/* We're marked for abortion. Don't do anything.
* Just return -- abort gets handled in _idler.
*/
task->finished = 1;
return 1;
}
{
/* We're marked for abortion. Don't do anything.
* Just return -- abort gets handled in _idler.
*/
task->finished = 1;
return 1;
}
if (_e_fm_op_handle_overwrite(task)) return 1;
if (S_ISDIR(task->src.st.st_mode))
{
if (S_ISDIR(task->src.st.st_mode))
{
if (_e_fm_op_copy_dir(task)) return 1;
}
else if (S_ISLNK(task->src.st.st_mode))
{
}
else if (S_ISLNK(task->src.st.st_mode))
{
if (_e_fm_op_copy_link(task)) return 1;
}
else if (S_ISFIFO(task->src.st.st_mode))
{
}
else if (S_ISFIFO(task->src.st.st_mode))
{
if (_e_fm_op_copy_fifo(task)) return 1;
}
else if (S_ISREG(task->src.st.st_mode))
{
}
else if (S_ISREG(task->src.st.st_mode))
{
if (_e_fm_op_open_files(task)) return 1;
}
}
@ -1362,7 +1367,7 @@ _e_fm_op_copy_atom(E_Fm_Op_Task * task)
}
static int
_e_fm_op_scan_atom(E_Fm_Op_Task * task)
_e_fm_op_scan_atom(E_Fm_Op_Task *task)
{
E_Fm_Op_Task *ctask, *rtask;
@ -1457,7 +1462,7 @@ _e_fm_op_scan_atom(E_Fm_Op_Task * task)
rtask->src.name = eina_stringshare_add(task->src.name);
memcpy(&(rtask->src.st), &(task->src.st), sizeof(struct stat));
if (task->dst.name)
rtask->dst.name = eina_stringshare_add(task->dst.name);
rtask->dst.name = eina_stringshare_add(task->dst.name);
rtask->type = E_FM_OP_SYMLINK;
_e_fm_op_work_queue = eina_list_prepend(_e_fm_op_work_queue, rtask);
@ -1467,7 +1472,7 @@ _e_fm_op_scan_atom(E_Fm_Op_Task * task)
}
static int
_e_fm_op_copy_stat_info_atom(E_Fm_Op_Task * task)
_e_fm_op_copy_stat_info_atom(E_Fm_Op_Task *task)
{
E_FM_OP_DEBUG("Stat: %s --> %s\n", task->src.name, task->dst.name);
@ -1498,7 +1503,7 @@ _e_fm_op_symlink_atom(E_Fm_Op_Task *task)
}
static int
_e_fm_op_remove_atom(E_Fm_Op_Task * task)
_e_fm_op_remove_atom(E_Fm_Op_Task *task)
{
if (_e_fm_op_abort) return 1;
@ -1506,19 +1511,19 @@ _e_fm_op_remove_atom(E_Fm_Op_Task * task)
if (S_ISDIR(task->src.st.st_mode))
{
if (rmdir(task->src.name) == -1)
{
if (errno == ENOTEMPTY)
{
if (rmdir(task->src.name) == -1)
{
if (errno == ENOTEMPTY)
{
E_FM_OP_DEBUG("Attempt to remove non-empty directory.\n");
/* This should never happen due to way tasks are added to the work queue. If this happens (for example new files were created after the scan was complete), implicitly delete everything. */
/* This should never happen due to way tasks are added to the work queue. If this happens (for example new files were created after the scan was complete), implicitly delete everything. */
ecore_file_recursive_rm(task->src.name);
task->finished = 1; /* Make sure that task is removed. */
return 1;
}
else
return 1;
}
else
_E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot remove directory '%s': %s.", task->src.name);
}
}
}
else if (unlink(task->src.name) == -1)
_E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_ERROR, "Cannot remove file '%s': %s.", task->src.name);
@ -1530,3 +1535,4 @@ _e_fm_op_remove_atom(E_Fm_Op_Task * task)
return 1;
}