Never thought this would happen to me, but there you go. ¯\_(ツ)_/¯
I ran a build script from a repository inside the wrong directory without looking at the source first. Here's the script Scripts/BuildLocalWheelLinux.sh
:
cd ../Dependencies/cpython
mkdir debug
cd debug
../configure --with-pydebug --enable-shared
make
cd ../../..
cd ..
mkdir -p cmake-build-local
cd cmake-build-local
rm -rf *
cmake .. -DMVDIST_ONLY=True -DMVPY_VERSION=0 -DMVDPG_VERSION=local_build
make -j
cd ..
cd Distribution
python3 BuildPythonWheel.py ../cmake-build-local/[redacted]/core.so 0
python3 -m ensurepip
python3 -m pip install --upgrade pip
[more pip install stuff]
python3 -m setup bdist_wheel --plat-name manylinux1_x86_64 --dist-dir ../dist
cd ..
cd Scripts
The dangerous part seems to be
mkdir -p cmake-build-local
cd cmake-build-local
rm -rf *
But thinking about it, it actually seems like it couldn't possibly go wrong.
The way you're supposed to run this script is cd Scripts; ./BuildLocalWheelLinux.sh
. When I ran it the first time, it showed an error on the very last line (as I learned afterwards). I was in a hurry, so I though "maybe the docs are outdated, I'll try running from the project root instead. So I ran ./Scripts/BuildLocalWheelLinux.sh
. Suddenly, vscodes theme and zoom level changed, my zsh terminal config was reset, terminal fonts were set to default, and I Ctrl+C'd once I realized what was happening.
There are some files remaining, but there's no obvious pattern to them:
$ ls -la
total 216
drwx------ 27 felix felix 4096 May 12 18:08 .
drwxr-xr-x 3 root root 4096 Apr 15 16:39 ..
-rw------- 1 felix felix 12752 Apr 19 11:07 .bash_history
-rw-r--r-- 1 felix felix 3980 Apr 15 13:40 .bashrc
drwxrwxrwx 7 felix felix 4096 May 12 18:25 .cache
drwx------ 8 felix felix 4096 May 12 18:26 .config
drwx------ 3 root root 4096 Apr 13 21:40 .dbus
drwx------ 2 felix felix 4096 Apr 30 12:18 .docker
drwxr-xr-x 8 felix felix 4096 Apr 15 13:40 .dotfiles
-rw------- 1 felix felix 8980 Apr 13 18:10 examples.desktop
-rw-r--r-- 1 felix felix 196 Apr 19 15:19 .gitconfig
-rw-r--r-- 1 felix felix 55 Apr 16 13:56 .gitconfig.old
-rw-r--r-- 1 felix felix 1040 Apr 15 13:40 .gitmodules
drwx------ 3 felix felix 4096 May 6 10:10 .gnupg
-rw-r--r-- 1 felix felix 1848 May 5 14:24 heartbeat.tcl
-rw------- 1 felix felix 1610 Apr 13 20:36 .ICEauthority
drwxr-xr-x 5 felix felix 4096 Apr 21 16:39 .ipython
drwxr-xr-x 2 felix felix 4096 May 4 09:35 .jupyter
-rw------- 1 felix felix 161 Apr 27 14:23 .lesshst
drwx------ 3 felix felix 4096 May 12 18:08 .local
-rw-r--r-- 1 felix felix 140 Apr 29 17:54 minicom.log
drwx------ 5 felix felix 4096 Apr 13 18:25 .mozilla
drwxr-xr-x 2 felix felix 4096 Apr 13 18:10 Music
drwxr-xr-x 6 felix felix 4096 May 12 17:16 Nextcloud
-rw-r--r-- 1 felix felix 52 Apr 16 11:43 .nix-channels
-rw------- 1 felix felix 1681 Apr 20 10:33 nohup.out
drwx------ 3 felix felix 4096 Apr 15 11:16 .pki
-rw------- 1 felix felix 946 Apr 16 11:43 .profile
drwxr-xr-x 2 felix felix 4096 Apr 13 18:10 Public
drwxr-xr-x 2 felix felix 4096 May 12 18:08 .pylint.d
-rw------- 1 felix felix 1984 May 12 18:06 .pythonhist
-rw-r--r-- 1 felix felix 2443 Apr 19 13:40 README.md
drwxr-xr-x 13 felix felix 4096 May 12 18:08 repos
drwxr-xr-x 6 felix felix 4096 Apr 19 11:08 snap
drwx------ 3 felix felix 4096 May 5 15:33 .ssh
drwxr-xr-x 5 felix felix 4096 Apr 26 17:39 .stm32cubeide
drwxr-xr-x 5 felix felix 4096 May 5 15:52 .stm32cubemx
drwxr-xr-x 2 felix felix 4096 Apr 23 11:44 .stmcube
drwxr-xr-x 2 felix felix 4096 Apr 13 18:10 Templates
drwxr-xr-x 3 felix felix 4096 Apr 19 11:57 test
drwxr-xr-x 2 felix felix 4096 Apr 13 18:10 Videos
-rw------- 1 felix felix 14313 May 12 10:45 .viminfo
-rw-r--r-- 1 felix felix 816 Apr 15 13:40 .vimrc
drwxr-xr-x 3 felix felix 4096 Apr 16 12:08 .vscode
-rw-r--r-- 1 felix felix 2321 Apr 19 18:47 weird_bug.txt
-rw-r--r-- 1 felix felix 162 Apr 15 13:40 .xprofile
.config
is gone, as well as some standard XDG dirs like Pictures and Desktop, but .bashrc is still there. .nix-channels
is still there, but .nix-defexpr
was nuked.
So, this leads me to two questions:
- What went wrong? I'd like to fix this build script and make a PR to prevent this from happening in the future.
- What order were the files deleted in? Obviously not in alphabetical order, but
*
expands in alphabetical order, so something else is going on here, it seems.
rm
would use thedirectory order
. More details here: unix.stackexchange.com/questions/13451 . It would be like the default ordering offind
's output.mkdir
fails and the directory didn't already exist, thecd
will fail, and it's game over.cd ../Dependencies/cpython
. That can be done by putting a&&
at the end of every command. There is more to it because sometimes it's ok for a command to fail, but that can be handled as well.set -e
at the beginning is a more effective way of doing this.set -e
has its own issues.cd foo || exit 1
is more explicit with fewer surprises.