chmod handling

 * prefer os.open instead of open && os.chmod
 * prefer os.fchmod when fd exists