Prevent importing apkg file when copying error

Fix a bug in #665