fix(sync): cleanup DB before syncing files to DB to avoid FileNotFoundException
Solution
The idea of the sync command is to essentially mirror what the filesystem to the DB, so the filesystem is the source of truth here, right? This also means that cleaning up the DB before updating from the filesystem should work, because the DB entries are updated anyway.
Issue
When there are Content Section Layout entries in the DB that don't exist on the filesystem anymore, a FileNotFoundException
was thrown. This was due to the fact that the sync command tries to read the CSLs' "index" file but could not find it. Removing the DB entry first based on what is on the filesystem solves this issue.
Disclaimer
I am not 100% sure what happens during the sync process, I did some debugging and did not find any issues with this solution, but you guys know the system way better than me