Describe the bug
When performing an in-place reformat, if the disk is full and black cannot write to disk, instead of leaving the file untouched it wipes the entire file, or corrupts it.
To Reproduce
- Fill up the disk
- Attempt to reformat a target python file
- Observe:
python3 -m black target.py
error: cannot format target.py: [Errno 28] No space left on device
Oh no! \U0001f4a5 \U0001f494 \U0001f4a5
1 file failed to reformat.
- The file is now corrupt or in some cases completely wiped.
Example:
qlyoung@host ~> md5sum target.py
3053e7e42131f8a2295d07ab3f70442d target.py
qlyoung@host ~> df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda 20G 19G 78M 100% /
qlyoung@host ~> cat /dev/zero > bingus
cat: write error: No space left on device
qlyoung@host ~> df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda 20G 19G 0 100% /
qlyoung@host ~> python3 -m black target.py
error: cannot format target.py: [Errno 28] No space left on device
Oh no! \U0001f4a5 \U0001f494 \U0001f4a5
1 file failed to reformat.
qlyoung@host ~> md5sum target.py
9640bcda965d5b519ae09ac7d3e87a91 target.py
In this case the end of the file was truncated. In the case that caused me to notice this bug, the entire file was wiped.
Expected behavior
The file should be left with its original contents
Environment (please complete the following information):
~> lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
~> python --version
Python 3.8.11
~> python -m black --version
__main__.py, version 20.8b1
Does this bug also happen on main?
I'm too sad to find out
Additional context
😢
Describe the bug
When performing an in-place reformat, if the disk is full and black cannot write to disk, instead of leaving the file untouched it wipes the entire file, or corrupts it.
To Reproduce
Example:
In this case the end of the file was truncated. In the case that caused me to notice this bug, the entire file was wiped.
Expected behavior
The file should be left with its original contents
Environment (please complete the following information):
Does this bug also happen on main?
I'm too sad to find out
Additional context
😢