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

« back to all changes in this revision

Viewing changes to src/mvJob.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) 1996-2007 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
20
#include <config.h>
24
23
#include "mvJob.h"
25
24
#include "misc.h"
26
25
 
27
 
mvJob::mvJob(FileAccess *session,const char *from,const char *to) : SessionJob(session)
28
 
{
29
 
   failed=0;
30
 
   if(last_char(to)=='/')
31
 
   {
32
 
      const char *from_bn=basename_ptr(from);
33
 
      char *to1=alloca_strdup2(to,strlen(from_bn));
34
 
      strcat(to1,from_bn);
35
 
      to=to1;
36
 
   }
37
 
   session->Rename(from,to);
 
26
mvJob::mvJob(FileAccess *session,const char *f,const char *t,FA::open_mode m1)
 
27
 : SessionJob(session), from(f), to(t), m(m1),
 
28
   remove_target(false), failed(false), done(false)
 
29
{
 
30
   if(to.last_char()=='/')
 
31
      to.append(basename_ptr(from));
 
32
   doOpen();
 
33
}
 
34
 
 
35
void mvJob::doOpen() const
 
36
{
 
37
   if(remove_target)
 
38
      session->Open(to,FA::REMOVE);
 
39
   else
 
40
      session->Open2(from,to,m);
38
41
}
39
42
 
40
43
int mvJob::Do()
43
46
      return STALL;
44
47
 
45
48
   int res=session->Done();
46
 
   if(res==FA::IN_PROGRESS)
 
49
   if(res==FA::IN_PROGRESS || res==FA::DO_AGAIN)
47
50
      return STALL;
48
 
   if(res==FA::OK)
49
 
   {
50
 
      session->Close();
51
 
      return MOVED;
 
51
   if(res!=FA::OK && !remove_target) {
 
52
      fprintf(stderr,"%s: %s\n",cmd(),session->StrError(res));
 
53
      done=failed=true;
52
54
   }
53
 
   if(res==FA::DO_AGAIN)
54
 
      return STALL;
55
 
   fprintf(stderr,"%s\n",session->StrError(res));
56
 
   failed=1;
57
55
   session->Close();
 
56
   if(remove_target) {
 
57
      remove_target=false;
 
58
      doOpen();
 
59
   } else
 
60
      done=true;
58
61
   return MOVED;
59
62
}
60
63
 
61
 
void  mvJob::PrintStatus(int v,const char *prefix)
 
64
xstring& mvJob::FormatStatus(xstring& s,int v,const char *prefix)
62
65
{
63
 
   SessionJob::PrintStatus(v,prefix);
 
66
   SessionJob::FormatStatus(s,v,prefix);
64
67
   if(Done())
65
 
      return;
66
 
   printf("%s[%s]\n",prefix,session->CurrentStatus());
 
68
      return s;
 
69
   if(remove_target)
 
70
      s.appendf("%srm %s [%s]\n",prefix,to.get(),session->CurrentStatus());
 
71
   else
 
72
      s.appendf("%s%s %s=>%s [%s]\n",prefix,cmd(),from.get(),to.get(),session->CurrentStatus());
 
73
   return s;
67
74
}
68
75
 
69
76
void  mvJob::ShowRunStatus(const SMTaskRef<StatusLine>& s)
70
77
{
71
 
   if(!Done())
72
 
      s->Show("[%s]",session->CurrentStatus());
 
78
   if(Done())
 
79
      return;
 
80
   if(remove_target)
 
81
      s->Show("rm %s [%s]\n",to.get(),session->CurrentStatus());
 
82
   else
 
83
      s->Show("%s %s=>%s [%s]\n",cmd(),from.get(),to.get(),session->CurrentStatus());
73
84
}
74
85
 
75
86
void  mvJob::SayFinal()
76
87
{
77
88
   if(failed)
78
89
      return;
79
 
   // xgettext:c-format
80
 
   printf(_("rename successful\n"));
 
90
   if(m==FA::RENAME) {
 
91
      // xgettext:c-format
 
92
      printf(_("rename successful\n"));
 
93
   }
81
94
}