mirror of
https://github.com/upa/mscp.git
synced 2026-05-13 13:57:30 +08:00
add copy start and done output
These fputs should be wrapped in a function and protected by a lock. todo.
This commit is contained in:
11
src/file.c
11
src/file.c
@@ -487,6 +487,7 @@ struct chunk *chunk_acquire(struct list_head *chunk_list)
|
|||||||
|
|
||||||
int chunk_prepare(struct chunk *c, sftp_session sftp)
|
int chunk_prepare(struct chunk *c, sftp_session sftp)
|
||||||
{
|
{
|
||||||
|
char output[PATH_MAX + 32];
|
||||||
struct file *f = c->f;
|
struct file *f = c->f;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
@@ -496,6 +497,9 @@ int chunk_prepare(struct chunk *c, sftp_session sftp)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
snprintf(output, sizeof(output), "\r\033[Kcopy start: %s\n", f->path);
|
||||||
|
fputs(output, stderr);
|
||||||
|
fflush(stderr);
|
||||||
f->state = FILE_STATE_OPENED;
|
f->state = FILE_STATE_OPENED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -727,6 +731,7 @@ int chunk_copy(struct chunk *c, sftp_session sftp, size_t sftp_buf_sz, size_t io
|
|||||||
{
|
{
|
||||||
struct file *f = c->f;
|
struct file *f = c->f;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
char output[PATH_MAX + 16];
|
||||||
|
|
||||||
pr_debug("copy %s %s -> %s %s off=0x%010lx\n",
|
pr_debug("copy %s %s -> %s %s off=0x%010lx\n",
|
||||||
f->path, f->remote ? "(remote)" : "(local)",
|
f->path, f->remote ? "(remote)" : "(local)",
|
||||||
@@ -746,8 +751,12 @@ int chunk_copy(struct chunk *c, sftp_session sftp, size_t sftp_buf_sz, size_t io
|
|||||||
f->path, f->remote ? "(remote)" : "(local)",
|
f->path, f->remote ? "(remote)" : "(local)",
|
||||||
f->dst_path, f->dst_remote ? "(remote)" : "(local)", c->off);
|
f->dst_path, f->dst_remote ? "(remote)" : "(local)", c->off);
|
||||||
|
|
||||||
if (refcnt_dec(&f->refcnt) == 0)
|
if (refcnt_dec(&f->refcnt) == 0) {
|
||||||
|
snprintf(output, sizeof(output), "\r\033[Kcopy done: %s\n", f->path);
|
||||||
|
fputs(output, stderr);
|
||||||
|
fflush(stderr);
|
||||||
f->state = FILE_STATE_DONE;
|
f->state = FILE_STATE_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/main.c
43
src/main.c
@@ -428,34 +428,31 @@ static void print_progress_bar(double percent, char *suffix)
|
|||||||
* [=======> ] XX.X% SUFFIX
|
* [=======> ] XX.X% SUFFIX
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
|
||||||
return; /* XXX */
|
return; /* XXX */
|
||||||
|
bar_width = min(sizeof(buf), ws.ws_col) - strlen(suffix) - 8;
|
||||||
|
|
||||||
|
if (bar_width > 8) {
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
thresh = floor(bar_width * (percent / 100)) - 1;
|
||||||
|
|
||||||
|
for (n = 1; n < bar_width - 1; n++) {
|
||||||
|
if (n <= thresh)
|
||||||
|
buf[n] = '=';
|
||||||
|
else
|
||||||
|
buf[n] = ' ';
|
||||||
|
}
|
||||||
|
buf[thresh] = '>';
|
||||||
|
buf[0] = '[';
|
||||||
|
buf[bar_width - 1] = ']';
|
||||||
|
snprintf(buf + bar_width, sizeof(buf) - bar_width,
|
||||||
|
" %3d%% ", (int)floor(percent));
|
||||||
|
}
|
||||||
|
|
||||||
fputs("\r\033[K", stderr);
|
fputs("\r\033[K", stderr);
|
||||||
|
|
||||||
bar_width = ws.ws_col - strlen(suffix) - 8;
|
|
||||||
if (bar_width < 0)
|
|
||||||
goto suffix_only;
|
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
thresh = floor(bar_width * (percent / 100)) - 1;
|
|
||||||
|
|
||||||
|
|
||||||
for (n = 1; n < bar_width - 1; n++) {
|
|
||||||
if (n <= thresh)
|
|
||||||
buf[n] = '=';
|
|
||||||
else
|
|
||||||
buf[n] = ' ';
|
|
||||||
}
|
|
||||||
buf[thresh] = '>';
|
|
||||||
buf[0] = '[';
|
|
||||||
buf[bar_width - 1] = ']';
|
|
||||||
|
|
||||||
snprintf(buf + bar_width, sizeof(buf) - bar_width,
|
|
||||||
" %3d%% ", (int)floor(percent));
|
|
||||||
|
|
||||||
fputs(buf, stderr);
|
fputs(buf, stderr);
|
||||||
suffix_only:
|
|
||||||
fputs(suffix, stderr);
|
fputs(suffix, stderr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user