On Mon, Feb 03, 2014 at 02:59:07PM +0200, vasos g wrote:
> I am using to reliably upload files with a method I call "mv&rm". It
> merely consists of: a) upload to a staging area. b) move prod to a
> templocation c) move stage to prod. d) rm templocation. I suppose
> you can imagine possible uses of this. One thing that I suggest is
> to implement this feature, which is something involving a lot of
> work I suppose.

I think this operation can vary greatly and can be implemented as a script.

> Besides this, I can implement this behavior with a lftp script.
> Another thing that I need, in order to implement this behaviour via
> an lftp script is the ability to execute a group of commands
> conditionally when a command fails. I want this to happen not in a
> subshell (as the "(") because I want to call "exit top".

Please try attached patch which improves "exit" behavoir and also
adds "exit parent".

Thus these commands work as expected:
   ((echo aaa; exit) echo bbb)
   ((echo aaa; exit parent) echo bbb)
   ((echo aaa; exit top) echo bbb)

--
   Alexander.
diff --git a/src/CmdExec.cc b/src/CmdExec.cc
index abf50fb..faf68e3 100644
--- a/src/CmdExec.cc
+++ b/src/CmdExec.cc
@@ -822,12 +822,12 @@ void CmdExec::init(LocalDirectory *c)
    Reconfig();
 }
 CmdExec::CmdExec(FileAccess *s,LocalDirectory *c)
-   : SessionJob(s?s:new DummyProto)
+   : SessionJob(s?s:new DummyProto), parent_exec(0)
 {
    init(c);
 }
-CmdExec::CmdExec(const CmdExec *parent)
-   : SessionJob(parent->session->Clone())
+CmdExec::CmdExec(CmdExec *parent)
+   : SessionJob(parent->session->Clone()), parent_exec(parent)
 {
    init(parent->cwd->Clone());
 }
diff --git a/src/CmdExec.h b/src/CmdExec.h
index 1f63346..752c4c7 100644
--- a/src/CmdExec.h
+++ b/src/CmdExec.h
@@ -69,6 +69,7 @@ public:
    int  prev_exit_code;
 
 private:
+   CmdExec *parent_exec;
    Buffer cmd_buf;
    bool partial_cmd;
    int alias_field; // length of expanded alias (and ttl for used_aliases)
@@ -176,7 +177,7 @@ public:
    void SuspendJob(Job *j);
 
    CmdExec(FileAccess *s,LocalDirectory *c);
-   CmdExec(const CmdExec *parent);
+   CmdExec(CmdExec *parent);
    ~CmdExec();
 
    bool Idle();        // when we have no command running and command buffer 
is empty
diff --git a/src/commands.cc b/src/commands.cc
index 34cdf91..72ab153 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -674,6 +674,11 @@ Job *CmdExec::builtin_exit()
         if(top)
            exec=top.get_non_const();
       }
+      else if(!strcmp(a,"parent"))
+      {
+        if(parent_exec)
+           exec=parent_exec;
+      }
       else if(!strcmp(a,"kill"))
       {
         kill=true;
@@ -699,9 +704,11 @@ Job *CmdExec::builtin_exit()
       detach=true;
    if(kill)
       Job::KillAll();
-   if(detach)
+   if(detach) {
+      for(CmdExec *e=this; e!=exec; e=e->parent_exec)
+        e->Exit(code);
       exec->Exit(code);
-   else {
+   } else {
       int loc=0;
       exec->SetAutoTerminateInBackground(true);
       eprintf(_(
@@ -733,6 +740,7 @@ void CmdExec::Exit(int code)
 {
    while(feeder)
       RemoveFeeder();
+   cmd_buf.Empty();
    if(interactive)
    {
       ListDoneJobs();
_______________________________________________
lftp mailing list
lftp@uniyar.ac.ru
http://univ.uniyar.ac.ru/mailman/listinfo/lftp

Reply via email to