summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2022-11-08 10:06:30 +0000
committerRyo Nakamura <upa@haeena.net>2022-11-08 10:06:30 +0000
commit8eb9e69c1c7936d8b8c773e7e30b52791d54c742 (patch)
treefd79590d26cb9f9a51cbe6940ff46e056c292e4f /src
parent04488f258c9de86671b48490ed1605b87991cc46 (diff)
fix incorrect ret handling for read/write
Diffstat (limited to 'src')
-rw-r--r--src/file.c18
-rw-r--r--src/main.c13
-rw-r--r--src/ssh.c8
-rw-r--r--src/ssh.h4
4 files changed, 27 insertions, 16 deletions
diff --git a/src/file.c b/src/file.c
index 69fe244..782a05d 100644
--- a/src/file.c
+++ b/src/file.c
@@ -623,7 +623,7 @@ static int chunk_copy_internal(struct chunk *c, int fd, sftp_file sf,
size_t sftp_buf_sz, size_t io_buf_sz,
bool reverse, size_t *counter)
{
- size_t remaind, read_bytes, write_bytes;
+ ssize_t read_bytes, write_bytes, remaind;
char buf[io_buf_sz];
/* if reverse is false, copy fd->sf (local to remote).
@@ -639,8 +639,12 @@ static int chunk_copy_internal(struct chunk *c, int fd, sftp_file sf,
sftp_buf_sz);
if (read_bytes < 0) {
- pr_err("failed to read %s: %s\n", c->f->dst_path,
- !reverse ? strerrno() : sftp_get_ssh_error(sf->sftp));
+ if (!reverse)
+ pr_err("failed to read %s: %s\n",
+ c->f->src_path, strerrno());
+ else
+ pr_err("failed to read %s: SFTP error code %d\n",
+ c->f->src_path, sftp_get_error(sf->sftp));
return -1;
}
@@ -650,8 +654,12 @@ static int chunk_copy_internal(struct chunk *c, int fd, sftp_file sf,
write_bytes = write(fd, buf, read_bytes);
if (write_bytes < 0) {
- pr_err("failed to write %s: %s\n", c->f->dst_path,
- !reverse ? strerrno() : sftp_get_ssh_error(sf->sftp));
+ if (!reverse)
+ pr_err("failed to write to %s: SFTP error code %d\n",
+ c->f->dst_path, sftp_get_error(sf->sftp));
+ else
+ pr_err("failed to write to %s: %s\n",
+ c->f->dst_path, strerrno());
return -1;
}
diff --git a/src/main.c b/src/main.c
index ed0b644..b0a4085 100644
--- a/src/main.c
+++ b/src/main.c
@@ -494,7 +494,7 @@ static void print_progress(struct timeval *start, struct timeval *end,
char *byte_units[] = { "B", "KB", "MB", "GB", "TB", "PB" };
char suffix[128];
int bps_u, byte_tu, byte_du;
- size_t total_round;
+ size_t total_round, done_round;
int percent;
double bps;
@@ -515,11 +515,14 @@ static void print_progress(struct timeval *start, struct timeval *end,
bps /= 1000;
percent = floor(((double)(done) / (double)total) * 100);
- for (byte_du = 0; done > 1000 && byte_du < array_size(byte_units) - 1; byte_du++)
- done /= 1024;
+
+ done_round = done;
+ for (byte_du = 0; done_round > 1000 && byte_du < array_size(byte_units) - 1;
+ byte_du++)
+ done_round /= 1024;
snprintf(suffix, sizeof(suffix), "%lu%s/%lu%s %.2f%s ",
- done, byte_units[byte_du], total_round, byte_units[byte_tu],
+ done_round, byte_units[byte_du], total_round, byte_units[byte_tu],
bps, bps_units[bps_u]);
print_progress_bar(percent, suffix);
@@ -582,7 +585,7 @@ void *mscp_monitor_thread(void *arg)
usleep(500000);
for (n = 0; n < nr_threads; n++) {
- done += threads[n].done;;
+ done += threads[n].done;
if (!threads[n].finished)
all_done = false;
}
diff --git a/src/ssh.c b/src/ssh.c
index 9ba7316..f5f737a 100644
--- a/src/ssh.c
+++ b/src/ssh.c
@@ -246,9 +246,9 @@ void ssh_sftp_close(sftp_session sftp)
}
-int sftp_write2(sftp_file sf, const void *buf, size_t len, size_t sftp_buf_sz)
+ssize_t sftp_write2(sftp_file sf, const void *buf, size_t len, size_t sftp_buf_sz)
{
- int ret, nbytes;
+ ssize_t ret, nbytes;
for (nbytes = 0; nbytes < len;) {
ret = sftp_write(sf, buf + nbytes,
@@ -260,9 +260,9 @@ int sftp_write2(sftp_file sf, const void *buf, size_t len, size_t sftp_buf_sz)
return nbytes;
}
-int sftp_read2(sftp_file sf, void *buf, size_t len, size_t sftp_buf_sz)
+ssize_t sftp_read2(sftp_file sf, void *buf, size_t len, size_t sftp_buf_sz)
{
- int ret, nbytes;
+ ssize_t ret, nbytes;
for (nbytes = 0; nbytes < len;) {
ret = sftp_read(sf, buf + nbytes,
diff --git a/src/ssh.h b/src/ssh.h
index 413fb6a..a073d4b 100644
--- a/src/ssh.h
+++ b/src/ssh.h
@@ -28,7 +28,7 @@ void ssh_sftp_close(sftp_session sftp);
#define sftp_get_ssh_error(sftp) ssh_get_error(sftp_ssh(sftp))
/* wrapping multiple sftp_read|write */
-int sftp_write2(sftp_file sf, const void *buf, size_t len, size_t sftp_buf_sz);
-int sftp_read2(sftp_file sf, void *buf, size_t len, size_t sftp_buf_sz);
+ssize_t sftp_write2(sftp_file sf, const void *buf, size_t len, size_t sftp_buf_sz);
+ssize_t sftp_read2(sftp_file sf, void *buf, size_t len, size_t sftp_buf_sz);
#endif /* _SSH_H_ */