I have a kiosk app written in python which is launched on startup (starting x server but not the window manager as I learnt about here), usbmount is installed to handle automatically mounting pen drives.
I want the application to be update-able by having a pen drive inserted on startup; this works, if the software folder is there it copies over the folder with a temp name, renames what is currently installed (and running) as a backup, renames the temp-named-copy and automatically restarts (executing '/usr/bin/sudo /sbin/shutdown -r now').
The whole software update works with no issues.
If the software isn't on the pen it can update a media folder or an ini configuration file, the process is essentially the same (copy with temp name, backup existing by renaming, rename temp-named-copy) but it doesn't restart. Once updating is complete it continues running the app reading these new files and this seems to work. I've output file sizes during this and they look good, I've used filezilla to pull the files from the pi and they look good, the app runs correctly with the new files.
But frequently (although not 100% reliably) when the raspberry pi/application is restarted without the usb pen drive (the pi is just switched off at the power, there is no shutdown command or procedure, the pen drive can be removed before or after it is switched off) the files that have been copied are empty; the files exist but have 0 size and no content.
I based the initial updater on this which uses shutil.copyfile but doesn't seem to do anything differently, trying through the GUI (using the LXDE winow manager) doesn't have the issue. The only difference between the software update (that works) and the resources update (that sometimes doesn't) is the restart which I would like to avoid in this case (complexity of determining if the resource update should happen or not).
As the files appear to copy but aren't there on restart I wondered if they exist in a cache but haven't been written to disk yet but there doesn't seem to be an shutil version of fsync to force that.
Any thoughts appreciated!