Pio lib -g uninstall removes source code

After installing and uninstalling a local library the source code is gone. I would expect that install and uninstall only affects the folders on the lib path (~/.platformio/lib/) and would not remove the original source code.

On a path with a TheLib directory:
pio lib -g install TheLib
pio lib -g uninstall TheLib
removes the TheLib folder in the local dir and not in ~/.platformio/lib/TheLib dir.

On a path with a TheLib directory:
pio lib -g install TheLib
pio lib -g uninstall TheLib
pio lib -g uninstall TheLib
removes first the TheLib folder in the local dir and then the ~/.platformio/lib/TheLib dir.

Is there a solution to this besides changing directory?

What is “local dir” for you? Could I reproduce this issue with PIO Library Registry library?

With local dir I mean the directory where I am.
E.g. my source is at ~/git/TheLib, I am in ~/git/, pwd gives ‘/home/gerben/git’

To reproduce this behavior:

mkdir TheLib
mkdir TheLib/src
touch TheLib/src/TheLib.h
touch TheLib/src/TheLib.cpp
touch TheLib/platformio.ini
cd TheLib
pio run
cd …
pio lib -g install ./TheLib
pio lib -g uninstall TheLib

I would expect my source code to still be under ~/git/TheLib and ~/.platformio/lib/TheLib removed.
But at this stage the source folder ~/git/TheLib is deleted by pio and ~/.platformio/lib/TheLib still exists.

Doing a second
pio lib -g uninstall TheLib
Removes ~/.platformio/lib/TheLib

It seems a bug. Please file an issue here Issues · platformio/platformio-core · GitHub and point a link to this discussion. Thanks!

Nevertheless, take a look at lib_extra_dirs, you do not need to install twice local library. Just add new extra storage and PIO will use your local library automatically.

Thank you for poining me to this option, I will try this out.