projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
A few seeking fixes.
[dcpomatic.git]
/
src
/
lib
/
scp_dcp_job.cc
diff --git
a/src/lib/scp_dcp_job.cc
b/src/lib/scp_dcp_job.cc
index 4878c7df476269209cbdd4f249b2973541e6ea59..a9fdfefda2f01671698c83279a624e5102ed894d 100644
(file)
--- a/
src/lib/scp_dcp_job.cc
+++ b/
src/lib/scp_dcp_job.cc
@@
-27,14
+27,19
@@
#include <fcntl.h>
#include <boost/filesystem.hpp>
#include <libssh/libssh.h>
#include <fcntl.h>
#include <boost/filesystem.hpp>
#include <libssh/libssh.h>
+#include "compose.hpp"
#include "scp_dcp_job.h"
#include "exceptions.h"
#include "config.h"
#include "log.h"
#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;
+#include "i18n.h"
+
+using std::string;
+using std::stringstream;
+using std::min;
+using boost::shared_ptr;
class SSHSession
{
class SSHSession
{
@@
-44,7
+49,7
@@
public:
{
session = ssh_new ();
if (session == 0) {
{
session = ssh_new ();
if (session == 0) {
- throw NetworkError (
"Could not start SSH session"
);
+ throw NetworkError (
_("could not start SSH session")
);
}
}
}
}
@@
-78,9
+83,7
@@
public:
{
scp = ssh_scp_new (s, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, Config::instance()->tms_path().c_str ());
if (!scp) {
{
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,9
+96,9
@@
public:
};
};
-SCPDCPJob::SCPDCPJob (shared_ptr<
const FilmState> s, Log* l
)
- : Job (
s, shared_ptr<const Options> (), l
)
- , _status (
"Waiting"
)
+SCPDCPJob::SCPDCPJob (shared_ptr<
Film> f
)
+ : Job (
f
)
+ , _status (
_("Waiting")
)
{
}
{
}
@@
-103,19
+106,17
@@
SCPDCPJob::SCPDCPJob (shared_ptr<const FilmState> s, Log* l)
string
SCPDCPJob::name () const
{
string
SCPDCPJob::name () const
{
- stringstream s;
- s << "Copy DCP to TMS";
- return s.str ();
+ return _("Copy DCP to TMS");
}
void
SCPDCPJob::run ()
{
}
void
SCPDCPJob::run ()
{
- _
log->log ("SCP DCP job starting"
);
+ _
film->log()->log (N_("SCP DCP job starting")
);
SSHSession ss;
SSHSession ss;
- set_status (
"Connecting"
);
+ set_status (
_("connecting")
);
ssh_options_set (ss.session, SSH_OPTIONS_HOST, Config::instance()->tms_ip().c_str ());
ssh_options_set (ss.session, SSH_OPTIONS_USER, Config::instance()->tms_user().c_str ());
ssh_options_set (ss.session, SSH_OPTIONS_HOST, Config::instance()->tms_ip().c_str ());
ssh_options_set (ss.session, SSH_OPTIONS_USER, Config::instance()->tms_user().c_str ());
@@
-124,91
+125,78
@@
SCPDCPJob::run ()
int r = ss.connect ();
if (r != SSH_OK) {
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) {
}
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) {
}
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) {
}
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, _f
s->name
.c_str(), S_IRWXU);
+ r = ssh_scp_push_directory (sc.scp, _f
ilm->dcp_name()
.c_str(), S_IRWXU);
if (r != SSH_OK) {
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 = _f
s->dir (_fs->name
);
+ string const dcp_dir = _f
ilm->dir (_film->dcp_name()
);
-
in
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);
+
boost::uintmax_
t bytes_to_transfer = 0;
+ 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);
}
}
-
in
t buffer_size = 64 * 1024;
+
boost::uintmax_
t buffer_size = 64 * 1024;
char buffer[buffer_size];
char buffer[buffer_size];
-
in
t bytes_transferred = 0;
+
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 ();
-#else
- string const leaf = i->leaf ();
-#endif
+ string const leaf = boost::filesystem::path(*i).leaf().generic_string ();
- set_status (
"Copying " + leaf
);
+ set_status (
String::compose (_("copying %1"), leaf)
);
-
int 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);
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) {
- stringstream s;
- s << "Could not open " << *i << " to send";
- throw NetworkError (s.str ());
+
+ FILE* f = fopen (boost::filesystem::path (*i).string().c_str(), N_("rb"));
+ if (f == 0) {
+ throw NetworkError (String::compose (_("Could not open %1 to send"), *i));
}
while (to_do > 0) {
int const t = min (to_do, buffer_size);
}
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 (boost::filesystem::path (*i).string());
+ }
+
r = ssh_scp_write (sc.scp, buffer, t);
if (r != SSH_OK) {
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;
set_progress ((double) bytes_transferred / bytes_to_transfer);
}
}
to_do -= t;
bytes_transferred += t;
set_progress ((double) bytes_transferred / bytes_to_transfer);
}
+
+ fclose (f);
}
set_progress (1);
}
set_progress (1);
- set_status (
"OK"
);
+ set_status (
N_("")
);
set_state (FINISHED_OK);
}
set_state (FINISHED_OK);
}
@@
-216,7
+204,12
@@
string
SCPDCPJob::status () const
{
boost::mutex::scoped_lock lm (_status_mutex);
SCPDCPJob::status () const
{
boost::mutex::scoped_lock lm (_status_mutex);
- return _status;
+ stringstream s;
+ s << Job::status ();
+ if (!_status.empty ()) {
+ s << N_("; ") << _status;
+ }
+ return s.str ();
}
void
}
void