~ubuntu-branches/debian/experimental/lftp/experimental

« back to all changes in this revision

Viewing changes to src/CopyJob.cc

  • Committer: Package Import Robot
  • Author(s): Noël Köthe
  • Date: 2015-08-21 16:06:22 UTC
  • mfrom: (1.1.20) (24.1.38 sid)
  • Revision ID: package-import@ubuntu.com-20150821160622-lckdmbiqx16wefgy
Tags: 4.6.4-1
new upstream release 2015-08-21

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * lftp and utils
 
2
 * lftp - file transfer program
3
3
 *
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)
5
5
 *
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.
15
15
 *
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/>.
19
18
 */
20
19
 
21
 
/* $Id: CopyJob.cc,v 1.45 2009/04/27 07:45:25 lav Exp $ */
22
 
 
23
20
#include <config.h>
24
21
#include "CopyJob.h"
25
22
#include "ArgV.h"
41
38
      return STALL;
42
39
   if(c->Error())
43
40
   {
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);
45
46
      done=true;
46
47
      return MOVED;
47
48
   }
98
99
 
99
100
   s->Show("%s", Status(s, false));
100
101
}
101
 
void CopyJob::PrintStatus(int v,const char *prefix)
 
102
xstring& CopyJob::FormatStatus(xstring& s,int v,const char *prefix)
102
103
{
103
104
   if(c->Done() || c->Error())
104
 
      return;
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.
110
 
    */
111
 
   if(!*c->GetStatus())
112
 
      return;
 
105
      return s;
 
106
   if(no_status)
 
107
      return s;
113
108
 
114
 
   printf("%s",prefix);
 
109
   s.append(prefix);
115
110
   const char *name=GetDispName();
116
 
   printf(COPY_STATUS);
117
 
   printf("\n");
 
111
   s.appendf(COPY_STATUS);
 
112
   s.append('\n');
 
113
   return s;
118
114
}
119
115
 
120
116
int CopyJob::AcceptSig(int sig)
164
160
                     (long long)bytes,long(time_spent+.5));
165
161
      double rate=bytes/time_spent;
166
162
      if(rate>=1)
167
 
         msg.appendf(" (%s)",Speedometer::GetStr(rate).get());
 
163
         msg.appendf(" (%s)",Speedometer::GetStrProper(rate).get());
168
164
      return msg;
169
165
   }
170
166
   return xstring::format(plural("%lld $#ll#byte|bytes$ transferred",
227
223
      errors++;
228
224
   count++;
229
225
   bytes+=j->GetBytesCount();
230
 
   time_spent+=j->GetTimeSpent();
231
226
   Delete(j);
232
227
   if(cp==j)
233
228
      cp=0;
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;
236
233
   return MOVED;
237
234
}
238
235
void CopyJobEnv::AddCopier(FileCopy *c,const char *n)
242
239
   if(ascii)
243
240
      c->Ascii();
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;
245
244
   AddWaiting(cp);
246
245
}
247
246
void CopyJobEnv::SetCopier(FileCopy *c,const char *n)
256
255
   AddCopier(c,n);
257
256
}
258
257
 
259
 
void CopyJobEnv::SayFinalWithPrefix(const char *p)
 
258
xstring& CopyJobEnv::FormatFinalWithPrefix(xstring& s,const char *p)
260
259
{
261
260
   if(no_status)
262
 
      return;
 
261
      return s;
263
262
   if(count==errors)
264
 
      return;
 
263
      return s;
265
264
   if(bytes)
266
 
      printf("%s%s\n",p,CopyJob::FormatBytesTimeRate(bytes,time_spent));
 
265
      s.appendf("%s%s\n",p,CopyJob::FormatBytesTimeRate(bytes,time_spent));
267
266
   if(errors>0)
268
267
   {
269
 
      printf("%s",p);
270
 
      printf(plural("Transfer of %d of %d $file|files$ failed\n",count),
 
268
      s.append(p);
 
269
      s.appendf(plural("Transfer of %d of %d $file|files$ failed\n",count),
271
270
         errors,count);
272
271
   }
273
272
   else if(count>1)
274
273
   {
275
 
      printf("%s",p);
276
 
      printf(plural("Total %d $file|files$ transferred\n",count),count);
 
274
      s.append(p);
 
275
      s.appendf(plural("Total %d $file|files$ transferred\n",count),count);
277
276
   }
 
277
   return s;
278
278
}
279
 
void CopyJobEnv::PrintStatus(int v,const char *prefix)
 
279
xstring& CopyJobEnv::FormatStatus(xstring& s,int v,const char *prefix)
280
280
{
281
 
   SessionJob::PrintStatus(v,prefix);
 
281
   SessionJob::FormatStatus(s,v,prefix);
282
282
   if(Done())
283
 
      SayFinalWithPrefix(prefix);
 
283
      FormatFinalWithPrefix(s,prefix);
 
284
   return s;
 
285
}
 
286
 
 
287
void CopyJobEnv::SayFinal()
 
288
{
 
289
   printf("%s",FormatFinalWithPrefix(xstring::get_tmp(""),"").get());
284
290
}
285
291
 
286
292
int CopyJobEnv::AcceptSig(int sig)