Prevent deadlock; introduce all_saved flag

Patch to prevent acquiring the same lock while saving a file because of
renaming; introduced an all_saved flag
Removed formal proof as simpler solution was found