Detegr/rust-ctrlc

Ctrl+C is awkward with Windows

Closed this issue · 5 comments

With Zola for example it says:

Press Ctrl+C to stop

but if you press that, it doesnt stop. You have to press it 3 times, or hold it. Then it does this:

Encountered an error: other os error
Enable a logger to see more information.

Are you using cmd.exe or powershell? Is the example of this repository working on your machine?

@Detegr actually readme_example works fine

In that case the issue is in how Zola handles the signal, I think.

Keats commented

Any idea what we are doing wrong in https://github.com/getzola/zola/blob/master/src/cmd/serve.rs#L282-L286 ?
I'll print the remove error message in case it's related but that seems unlikely

I would probably modify the handler to change an AtomicBool which would be checked in the loop (in addition to rx.recv()), and handle the cleanup outside of the signal handler. However, I don't see why your current solution would not work. Only thing that comes across my mind is that Windows likes to lock directories and files that are in use, and refuse to delete them. But then again, you throw the Result of remove_dir_all away, so that should not matter. Have you tried for example adding a debug print to the handler and see whether it gets called properly?