lock all files being written to when writing (except when the file has been opened in append mode)
closes #766