X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fscp_dcp_job.cc;h=22129f56cdf05e2edadda7baedce3378e012160f;hb=aeb20874df252fd8d36f5d3742ed8e34f2215367;hp=f62d2db8dd86bb78be6e440319ff0ae8dbb8a06d;hpb=475ecb67af7af522ec8796ea1bf0d16602c78273;p=dcpomatic.git diff --git a/src/lib/scp_dcp_job.cc b/src/lib/scp_dcp_job.cc index f62d2db8d..22129f56c 100644 --- a/src/lib/scp_dcp_job.cc +++ b/src/lib/scp_dcp_job.cc @@ -27,14 +27,17 @@ #include #include #include +#include "compose.hpp" #include "scp_dcp_job.h" #include "exceptions.h" #include "config.h" #include "log.h" -#include "film_state.h" +#include "film.h" -using namespace std; -using namespace boost; +using std::string; +using std::stringstream; +using std::min; +using boost::shared_ptr; class SSHSession { @@ -78,9 +81,7 @@ public: { scp = ssh_scp_new (s, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, Config::instance()->tms_path().c_str ()); if (!scp) { - stringstream s; - s << "Could not start SCP session (" << ssh_get_error (s) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not start SCP session (%1)", ssh_get_error (s))); } } @@ -93,8 +94,8 @@ public: }; -SCPDCPJob::SCPDCPJob (shared_ptr s, Log* l) - : Job (s, shared_ptr (), l) +SCPDCPJob::SCPDCPJob (shared_ptr f, shared_ptr req) + : Job (f, req) , _status ("Waiting") { @@ -103,15 +104,13 @@ SCPDCPJob::SCPDCPJob (shared_ptr s, Log* l) string SCPDCPJob::name () const { - stringstream s; - s << "Copy DCP to TMS"; - return s.str (); + return "Copy DCP to TMS"; } void SCPDCPJob::run () { - _log->log ("SCP DCP job starting"); + _film->log()->log ("SCP DCP job starting"); SSHSession ss; @@ -124,85 +123,71 @@ SCPDCPJob::run () int r = ss.connect (); if (r != SSH_OK) { - stringstream s; - s << "Could not connect to server " << Config::instance()->tms_ip() << " (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not connect to server %1 (%2)", Config::instance()->tms_ip(), ssh_get_error (ss.session))); } int const state = ssh_is_server_known (ss.session); if (state == SSH_SERVER_ERROR) { - stringstream s; - s << "SSH error (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("SSH error (%1)", ssh_get_error (ss.session))); } r = ssh_userauth_password (ss.session, 0, Config::instance()->tms_password().c_str ()); if (r != SSH_AUTH_SUCCESS) { - stringstream s; - s << "Failed to authenticate with server (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Failed to authenticate with server (%1)", ssh_get_error (ss.session))); } SSHSCP sc (ss.session); r = ssh_scp_init (sc.scp); if (r != SSH_OK) { - stringstream s; - s << "Could not start SCP session (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not start SCP session (%1)", ssh_get_error (ss.session))); } - r = ssh_scp_push_directory (sc.scp, _fs->name.c_str(), S_IRWXU); + r = ssh_scp_push_directory (sc.scp, _film->dcp_name().c_str(), S_IRWXU); if (r != SSH_OK) { - stringstream s; - s << "Could not create remote directory " << _fs->name << "(" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not create remote directory %1 (%2)", _film->dcp_name(), ssh_get_error (ss.session))); } - string const dcp_dir = _fs->dir (_fs->name); + string const dcp_dir = _film->dir (_film->dcp_name()); boost::uintmax_t bytes_to_transfer = 0; - for (filesystem::directory_iterator i = filesystem::directory_iterator (dcp_dir); i != filesystem::directory_iterator(); ++i) { - bytes_to_transfer += filesystem::file_size (*i); + for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (dcp_dir); i != boost::filesystem::directory_iterator(); ++i) { + bytes_to_transfer += boost::filesystem::file_size (*i); } boost::uintmax_t buffer_size = 64 * 1024; char buffer[buffer_size]; boost::uintmax_t bytes_transferred = 0; - for (filesystem::directory_iterator i = filesystem::directory_iterator (dcp_dir); i != filesystem::directory_iterator(); ++i) { + for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (dcp_dir); i != boost::filesystem::directory_iterator(); ++i) { /* Aah, the sweet smell of progress */ #if BOOST_FILESYSTEM_VERSION == 3 - string const leaf = filesystem::path(*i).leaf().generic_string (); + string const leaf = boost::filesystem::path(*i).leaf().generic_string (); #else string const leaf = i->leaf (); #endif set_status ("copying " + leaf); - boost::uintmax_t to_do = filesystem::file_size (*i); + boost::uintmax_t to_do = boost::filesystem::file_size (*i); ssh_scp_push_file (sc.scp, leaf.c_str(), to_do, S_IRUSR | S_IWUSR); - FILE* f = fopen (filesystem::path (*i).string().c_str(), "rb"); + FILE* f = fopen (boost::filesystem::path (*i).string().c_str(), "rb"); if (f == 0) { - stringstream s; - s << "Could not open " << *i << " to send"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not open %1 to send", *i)); } while (to_do > 0) { int const t = min (to_do, buffer_size); size_t const read = fread (buffer, 1, t, f); if (read != size_t (t)) { - throw ReadFileError (filesystem::path (*i).string()); + throw ReadFileError (boost::filesystem::path (*i).string()); } r = ssh_scp_write (sc.scp, buffer, t); if (r != SSH_OK) { - stringstream s; - s << "Could not write to remote file (" << ssh_get_error (ss.session) << ")"; - throw NetworkError (s.str ()); + throw NetworkError (String::compose ("Could not write to remote file (%1)", ssh_get_error (ss.session))); } to_do -= t; bytes_transferred += t;