fix process updating for secure delete operations, efm_op now requires libmath

SVN revision: 78864
This commit is contained in:
Mike Blumenkrantz 2012-11-02 13:44:37 +00:00
parent 2bd9c7f72c
commit 7de1d89a0b
2 changed files with 17 additions and 18 deletions

View File

@ -388,7 +388,7 @@ enlightenment_thumb_LDADD = @E_THUMB_LIBS@
enlightenment_fm_op_SOURCES = \ enlightenment_fm_op_SOURCES = \
e_fm_op.c e_fm_op.c
enlightenment_fm_op_LDADD = @E_FM_OP_LIBS@ enlightenment_fm_op_LDADD = @E_FM_OP_LIBS@ -lm
enlightenment_sys_SOURCES = \ enlightenment_sys_SOURCES = \
e_sys_main.c e_sys_main.c

View File

@ -21,6 +21,7 @@ extern "C"
void *alloca(size_t); void *alloca(size_t);
#endif #endif
#include <math.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -144,6 +145,8 @@ struct _E_Fm_Op_Task
} dst; } dst;
int started, finished; int started, finished;
unsigned int passes;
off_t pos;
void *data; void *data;
@ -419,6 +422,7 @@ _e_fm_op_task_new()
t->type = E_FM_OP_NONE; t->type = E_FM_OP_NONE;
t->overwrite = E_FM_OP_NONE; t->overwrite = E_FM_OP_NONE;
t->link = NULL; t->link = NULL;
t->pos = t->passes = 0;
return t; return t;
} }
@ -1157,7 +1161,7 @@ _e_fm_op_handle_overwrite(E_Fm_Op_Task *task)
else else
{ {
_e_fm_op_overwrite = 1; _e_fm_op_overwrite = 1;
_e_fm_op_update_progress_report_simple(0.0, task->src.name, task->dst.name); _e_fm_op_update_progress_report_simple(0, task->src.name, task->dst.name);
_E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_OVERWRITE, "%s", task->dst.name); _E_FM_OP_ERROR_SEND_WORK(task, E_FM_OP_OVERWRITE, "%s", task->dst.name);
} }
} }
@ -1221,7 +1225,7 @@ _e_fm_op_copy_link(E_Fm_Op_Task *task)
} }
E_FM_OP_DEBUG("Creating link from '%s' to '%s'\n", lnk_path, task->dst.name); E_FM_OP_DEBUG("Creating link from '%s' to '%s'\n", lnk_path, task->dst.name);
_e_fm_op_update_progress_report_simple(0.0, lnk_path, task->dst.name); _e_fm_op_update_progress_report_simple(0, lnk_path, task->dst.name);
if (symlink(lnk_path, task->dst.name) == -1) if (symlink(lnk_path, task->dst.name) == -1)
{ {
@ -1581,7 +1585,7 @@ _e_fm_op_symlink_atom(E_Fm_Op_Task *task)
if (_e_fm_op_handle_overwrite(task)) return 1; if (_e_fm_op_handle_overwrite(task)) return 1;
E_FM_OP_DEBUG("Symlink: %s -> %s\n", task->src.name, task->dst.name); E_FM_OP_DEBUG("Symlink: %s -> %s\n", task->src.name, task->dst.name);
_e_fm_op_update_progress_report_simple(0.0, task->src.name, task->dst.name); _e_fm_op_update_progress_report_simple(0, task->src.name, task->dst.name);
if (symlink(task->src.name, task->dst.name) == -1) if (symlink(task->src.name, task->dst.name) == -1)
{ {
@ -1646,7 +1650,7 @@ _e_fm_op_rename_atom(E_Fm_Op_Task *task)
if (_e_fm_op_handle_overwrite(task)) return 1; if (_e_fm_op_handle_overwrite(task)) return 1;
E_FM_OP_DEBUG("Move: %s -> %s\n", task->src.name, task->dst.name); E_FM_OP_DEBUG("Move: %s -> %s\n", task->src.name, task->dst.name);
_e_fm_op_update_progress_report_simple(0.0, task->src.name, task->dst.name); _e_fm_op_update_progress_report_simple(0, task->src.name, task->dst.name);
if (rename(task->src.name, task->dst.name) == -1) if (rename(task->src.name, task->dst.name) == -1)
{ {
@ -1666,8 +1670,6 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
if (_e_fm_op_abort) goto finish; if (_e_fm_op_abort) goto finish;
static int fd = -1; static int fd = -1;
static char *buf = NULL; static char *buf = NULL;
static int passes = 0;
static off_t pos = 0;
off_t sz; off_t sz;
if (fd == -1) if (fd == -1)
@ -1681,7 +1683,7 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
if (task->src.st.st_nlink > 1) if (task->src.st.st_nlink > 1)
goto finish; goto finish;
if ((fd = open(task->src.name, O_WRONLY|O_NONBLOCK|O_NOFOLLOW, 0)) == -1) if ((fd = open(task->src.name, O_WRONLY|O_NOFOLLOW, 0)) == -1)
goto finish; goto finish;
if (fstat(fd, &st2) == -1) if (fstat(fd, &st2) == -1)
@ -1698,7 +1700,7 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
task->src.st.st_size = st2.st_size; task->src.st.st_size = st2.st_size;
} }
if (pos + READBUFSIZE > task->src.st.st_size) sz = task->src.st.st_size - pos; if (task->pos + READBUFSIZE > task->src.st.st_size) sz = task->src.st.st_size - task->pos;
else sz = READBUFSIZE; else sz = READBUFSIZE;
_e_fm_op_random_buf(buf, sz); _e_fm_op_random_buf(buf, sz);
@ -1707,22 +1709,21 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
if (fsync(fd) == -1) if (fsync(fd) == -1)
goto finish; goto finish;
pos += sz; task->pos += sz;
_e_fm_op_update_progress_report_simple((double) (pos + (passes * task->src.st.st_size)) / _e_fm_op_update_progress_report_simple(lround((double) ((task->pos + (task->passes * task->src.st.st_size)) /
(task->src.st.st_size * NB_PASS) * 100, (double)(task->src.st.st_size * NB_PASS)) * 100.),
"/dev/urandom", task->src.name); "/dev/urandom", task->src.name);
if (pos >= task->src.st.st_size) if (task->pos >= task->src.st.st_size)
{ {
passes++; task->passes++;
if (passes == NB_PASS) if (task->passes == NB_PASS)
goto finish; goto finish;
if (lseek(fd, SEEK_SET, 0) == -1) if (lseek(fd, SEEK_SET, 0) == -1)
goto finish; goto finish;
pos = 0;
return 1; return 1;
} }
@ -1732,8 +1733,6 @@ finish:
close(fd); close(fd);
fd = -1; fd = -1;
E_FREE(buf); E_FREE(buf);
passes = 0;
pos = 0;
task->finished = 1; task->finished = 1;
return 1; return 1;
} }