Import r39579 from trunk by nobu

Fix for unusal cases again.  install to a temporary directory once and
move instaled files to the destination directory, if it is same as the
current directory.  [Bug #7698]