diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-24 20:53:46 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-24 20:53:46 +0100 |
| commit | 7a8f7e87d631adec94b6b2e61e524ee9424e8284 (patch) | |
| tree | 8b0f0876ca78ff30fb32b49987c1102613874417 /src | |
| parent | 13e4b80a7d44b7c4bc75bef191d6d5621b25ceab (diff) | |
Use stdio for reading jobs for SCP.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/exceptions.h | 2 | ||||
| -rw-r--r-- | src/lib/scp_dcp_job.cc | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index b66d7baa7..6b567805b 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -127,7 +127,7 @@ public: /** @param f File that we were trying to read from. * @param e errno value, or 0. */ - ReadFileError (std::string f, int e) + ReadFileError (std::string f, int e = 0) : FileError ("", f) { std::stringstream s; diff --git a/src/lib/scp_dcp_job.cc b/src/lib/scp_dcp_job.cc index ffa04e018..760e85bd0 100644 --- a/src/lib/scp_dcp_job.cc +++ b/src/lib/scp_dcp_job.cc @@ -183,9 +183,9 @@ SCPDCPJob::run () int to_do = filesystem::file_size (*i); ssh_scp_push_file (sc.scp, leaf.c_str(), to_do, S_IRUSR | S_IWUSR); - - int fd = open (filesystem::path (*i).string().c_str(), O_RDONLY); - if (fd == 0) { + + FILE* f = fopen (filesystem::path (*i).string().c_str(), "rb"); + if (f == 0) { stringstream s; s << "Could not open " << *i << " to send"; throw NetworkError (s.str ()); @@ -193,7 +193,11 @@ SCPDCPJob::run () while (to_do > 0) { int const t = min (to_do, buffer_size); - read (fd, buffer, t); + size_t const read = fread (buffer, 1, t, f); + if (read != size_t (t)) { + throw ReadFileError (filesystem::path (*i).string()); + } + r = ssh_scp_write (sc.scp, buffer, t); if (r != SSH_OK) { stringstream s; @@ -205,6 +209,8 @@ SCPDCPJob::run () set_progress ((double) bytes_transferred / bytes_to_transfer); } + + fclose (f); } set_progress (1); |
