The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6064
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === So we can indicate that the initial server side handling cannot be canceled. As soon as the transfer does begin, it is cancelable and ctrl+c will work. Closes #6062 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From dd4a78de7561b7722caa43817c47e367bd0ff828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Sun, 11 Aug 2019 21:41:28 -0400 Subject: [PATCH] lxc/file: Intercept user cancelation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So we can indicate that the initial server side handling cannot be canceled. As soon as the transfer does begin, it is cancelable and ctrl+c will work. Closes #6062 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxc/file.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lxc/file.go b/lxc/file.go index b0e896f1d3..bf6251d6b3 100644 --- a/lxc/file.go +++ b/lxc/file.go @@ -6,6 +6,7 @@ import ( "io" "io/ioutil" "os" + "os/signal" "path" "path/filepath" "strconv" @@ -35,6 +36,37 @@ type cmdFile struct { flagRecursive bool } +func fileGetWrapper(server lxd.ContainerServer, container string, path string) (buf io.ReadCloser, resp *lxd.ContainerFileResponse, err error) { + // Signal handling + chSignal := make(chan os.Signal) + signal.Notify(chSignal, os.Interrupt) + + // Operation handling + chDone := make(chan bool) + go func() { + buf, resp, err = server.GetContainerFile(container, path) + close(chDone) + }() + + count := 0 + for { + var err error + + select { + case <-chDone: + return buf, resp, err + case <-chSignal: + count++ + + if count == 3 { + return nil, nil, fmt.Errorf(i18n.G("User signaled us three times, exiting. The remote operation will keep running")) + } + + fmt.Println(i18n.G("Early server side processing of file tranfer requests cannot be canceled (interrupt two more times to force)")) + } + } +} + func (c *cmdFile) Command() *cobra.Command { cmd := &cobra.Command{} cmd.Use = i18n.G("file") @@ -245,7 +277,7 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error { return fmt.Errorf(i18n.G("Invalid source %s"), resource.name) } - buf, resp, err := resource.server.GetContainerFile(pathSpec[0], pathSpec[1]) + buf, resp, err := fileGetWrapper(resource.server, pathSpec[0], pathSpec[1]) if err != nil { return err }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel