2
* lftp - file transfer program
4
* Copyright (c) 1999-2008 by Alexander V. Lukyanov (lav@yars.free.net)
4
* Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
14
14
* GNU General Public License for more details.
16
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
/* $Id: CopyJob.cc,v 1.45 2009/04/27 07:45:25 lav Exp $ */
23
20
#include <config.h>
24
21
#include "CopyJob.h"
44
eprintf("%s: %s\n",op.get(),c->ErrorText());
41
const char *error=c->ErrorText();
42
const char *name=GetDispName();
43
if(!strstr(error,name) && op.ne(name))
44
error=xstring::cat(name,": ",error,NULL);
45
eprintf("%s: %s\n",op.get(),error);
99
100
s->Show("%s", Status(s, false));
101
void CopyJob::PrintStatus(int v,const char *prefix)
102
xstring& CopyJob::FormatStatus(xstring& s,int v,const char *prefix)
103
104
if(c->Done() || c->Error())
105
/* If neither of our FileCopyPeers have a status, we're something
106
* dumb like buffer->fd and have no meaningful status to print.
107
* (If that's the case, we're probably a child job, so our parent
108
* will be printing something anyway.) If an OutputJob actually
109
* attaches to a real output peer, we *do* want to print status.
115
110
const char *name=GetDispName();
111
s.appendf(COPY_STATUS);
120
116
int CopyJob::AcceptSig(int sig)
164
160
(long long)bytes,long(time_spent+.5));
165
161
double rate=bytes/time_spent;
167
msg.appendf(" (%s)",Speedometer::GetStr(rate).get());
163
msg.appendf(" (%s)",Speedometer::GetStrProper(rate).get());
170
166
return xstring::format(plural("%lld $#ll#byte|bytes$ transferred",
229
225
bytes+=j->GetBytesCount();
230
time_spent+=j->GetTimeSpent();
234
229
if(waiting_num>0 && cp==0)
235
230
cp=(CopyJob*)waiting[0];
231
if(waiting.count()==0)
232
time_spent+=now-transfer_start_ts;
238
235
void CopyJobEnv::AddCopier(FileCopy *c,const char *n)
244
241
cp=cj_new?cj_new->New(c,n,op):new CopyJob(c,n,op);
242
if(waiting.count()==0)
243
transfer_start_ts=now;
247
246
void CopyJobEnv::SetCopier(FileCopy *c,const char *n)
259
void CopyJobEnv::SayFinalWithPrefix(const char *p)
258
xstring& CopyJobEnv::FormatFinalWithPrefix(xstring& s,const char *p)
263
262
if(count==errors)
266
printf("%s%s\n",p,CopyJob::FormatBytesTimeRate(bytes,time_spent));
265
s.appendf("%s%s\n",p,CopyJob::FormatBytesTimeRate(bytes,time_spent));
270
printf(plural("Transfer of %d of %d $file|files$ failed\n",count),
269
s.appendf(plural("Transfer of %d of %d $file|files$ failed\n",count),
276
printf(plural("Total %d $file|files$ transferred\n",count),count);
275
s.appendf(plural("Total %d $file|files$ transferred\n",count),count);
279
void CopyJobEnv::PrintStatus(int v,const char *prefix)
279
xstring& CopyJobEnv::FormatStatus(xstring& s,int v,const char *prefix)
281
SessionJob::PrintStatus(v,prefix);
281
SessionJob::FormatStatus(s,v,prefix);
283
SayFinalWithPrefix(prefix);
283
FormatFinalWithPrefix(s,prefix);
287
void CopyJobEnv::SayFinal()
289
printf("%s",FormatFinalWithPrefix(xstring::get_tmp(""),"").get());
286
292
int CopyJobEnv::AcceptSig(int sig)