I found I was running out of space on my Trinket M0 super easily, and I wanted to share a tip for Mac OS that helped save me a lot of space (possibly dozens of KB on my very modest program). This is beyond clearing out needless visible files and hidden files (e.g. dotfiles).
While adafruit have done a really good job hinting to operating systems that they shouldn't write metadata to the drive (no_log etc), that doesn't stop Mac OS copying "extended attributes" on files if you copy-paste or drag them into the drive in the Finder. (This is explained by adafruit here under "Copy Files on Mac OSX Without Creating Hidden Files".)
For me, a newcomer to CircuitPython, these attributes were included when I copied the default main.py program, and some adafruit spi library files into the lib folder. A total of 5 files (~8.5KB of code). But it wouldn't fit in the 48KB drive, even after I cleared out all the junk I could find. (And emptied the trash ;P)
After a bit of research and learning about these extended attributes, I cleared them manually on every file. I was very surprised to see how much space it freed up on the drive. I went from having 0% free to about 50% free, which is over 20kb – enough for a decent main.py.
I love the command line, but I also find it super convenient to use the Finder. So I wrote a little bash script to automate stripping these attributes on all files it can find on the drive. I run this from within the /Volumes/CIRCUITPY dir when I'm running out of space.
strip_xattr.sh
- Code: Select all | TOGGLE FULL SIZE
cd /Volumes/CIRCUITPY
echo "Warning: This program will erase extended attributes on all files in" `pwd`
echo "Proceed?"
echo
read -p "Press Ctrl-C to abort, any other key to proceed..."
PRE_FREE_SPACE_KB=`df -Pk . | sed 1d | grep -v used | awk '{ print $4 "\t" }'`
find ./* | (
while read -r FILENAME; do
echo Cleaning "$FILENAME"
xattr "$FILENAME" | xargs -n 1 -I attr xattr -d attr "$FILENAME"
done;
)
POST_FREE_SPACE_KB=`df -Pk . | sed 1d | grep -v used | awk '{ print $4 "\t" }'`
echo "Done."
echo
echo "Space before: " $PRE_FREE_SPACE_KB "kb"
echo "Space after: " $POST_FREE_SPACE_KB "kb"
To run it, use your editor to copy this program to a file on the CIRCUITPY volume, e.g. "strip_xattr.sh". In Terminal, cd /Volumes/CIRCUITPY then ./strip_xattr.sh
I'm running Mac OS (Catalina 10.15), so perhaps it's something that Apple changed recently.
Anyway, I hope this helps someone. I also hope adafruit can find a way to cajole MacOS into omitting these extended attributes when they're copied onto the drive, although I'd be surprised if this is possible. :(