fix copyfile error handling