Skip to content
⌘ NSIS Forum Archive

Weird behaviour of "Rename" command

2 posts

Mircea M#

Weird behaviour of "Rename" command

Hi,

from time to time I encounter issues while performing a backup of the current $INSTDIR during the upgrade process.

In order to make sure that everything is closed and nothing blocks the move process, I am first closing everything that I know of and then, just to make sure, running LockedList on $INSTDIR and closing everything else that might still be open (like log files, for example).

Here are the functions I am using:

Function SilentSearchCallback
Pop $R0
Pop $R1
Pop $R2

${If} $R0 == -1
DetailPrint "ERROR: Could not close locked process: $R2!"
${Else}
DetailPrint "INFO: Closing locked process: $R2"
Push autoclose
${EndIf}
FunctionEnd

Function CloseLockedFiles
LockedList::AddFolder $INSTDIR
GetFunctionAddress $R0 SilentSearchCallback
LockedList::SilentSearch $R0
Pop $R0
DetailPrint $R0
SetAutoClose false
FunctionEnd
Then, in another function (that moves the existing folder), I use this:

	Detailprint "Prior installation will be moved to $FinalBackupPriorInstallationFolder"

Call CloseLockedFiles

Rename "$INSTDIR" "${TEMP_BACKUP_FOLDER}\ImageDiagnost"
IfErrors 0 move_to_temp_success
; Abort on error - some files are locked
${myLogText} "ERROR: Backup of prior installation files failed!"
${myLogText} "ERROR: Cannot move from $INSTDIR to ${TEMP_BACKUP_FOLDER}\ImageDiagnost"
${myLogText} "ERROR: Update installation aborted. Your existing installation is untouched."
abort "Update installation aborted. Your existing installation is untouched."
I then perform the following test:
  1. Start an executable in $INSTDIR (ex: putty)
  2. Open a log file (text file) from the $INSTDIR
  3. Have a folder from $INSTDIR open in Windows Explorer
  4. Run my installer


While executing the installer, putty.exe is closed, Notepad is closed (with the log file) but then the Rename command fails.
If at this point I try to rename the folder manually, it works!. The problem seems to be with renaming through NSIS. The folder where I try to move does not exist so there is nothing to overwrite.
Any idea why this might be happening? Could it be because I have a Windows Explorer open and NSIS has some trouble with that?

Thank you!
Mircea M#
After more tests I realized that it is indeed because of Windows Explorer. As soon as it has any folder from inside $INSTDIR open, NSIS can not rename $INSTDIR anymore.