write_locked_index(): add flag to avoid writing unchanged index