fabric/fabric — Issue #472: put() permanently fails after aborted upload of write-protected file with use_sudo=True
Author: bendyer
Created: 2011-11-07 10:08:00+00:00
State: open

If a connection failure is encountered between the upload to a hashed file location (sftp.py:208-213; sftp.py:224) and the sudo move operation (sftp.py:239-243), any subsequent attempt to upload that file will fail if the file is write-protected.

The most direct solution appears to be performing the sudo move before changing file permissions, by swapping the order of the two if blocks:
https://github.com/bendyer/fabric/commit/6d4e9b7cb594b656efd946832be784eb46e23924