This question already has an answer here:
Using Python, I scan Unix mounted volumes for files, then add or purge the filenames in a database, based on their existence. I've just realised that if the volume being scanned is unmounted for some reason, the scan will assume every filename on that volume should be purged! Yikes. Is there any better way to mount volumes or any suggestions at all?
About the only thing I can think of is to put a permanent dummy file on each volume which I check for before scanning, thereby ensuring that the volume is only scanned if the dummy file can be located.