fix bug when trying to write to non-writable files