Archive: SetOverwrite ifnewer not working ... why?


SetOverwrite ifnewer not working ... why?
Hi All.

I've been working NSIS for a while and have built an installer that works for me except for the fact that ifnewer does not appear to work for me. This is with NSIS v2.06 in Win98 and Win2k.

I think I have setup the SetOverwrite command properly, and I invoke it with the ifnewer argument. However, a test I recently did showed that it doesn't work, and I really want to know why / want to know how to fix it. Perhaps someone can help?

My test:

1) Build & run installer, installs file d:\path\fileA to c:\path\fileA.

2) Edit d:\path\fileA (add some text).

3) Re-build and run installer.

5) View c:\path\fileA. It's still the old fileA. not the new one that has the added text.

Isn't this wrong? Shouldn't the ifnewer attribute force the new fileA (from d:\path\fileA) to overwrite the old fileA (in c:\path\fileA)?

I've attached the relevant part of the build window.

Note that I do want ifnewer, not the default (on), for certain files.

Please please please someone show me what I've been doing wrong ...


I did a quick test and it works fine.
Is it possible that an error occured when trying to extract the file to c:\path\? (Have you tried looking for the error flag?)

Here's the code I used in my test:

Name "test"
outfile "Test File Overwrite.exe"
ShowInstDetails show

page instfiles

Section
CreateDirectory "C:\temp\NSIS_TEST\installdir"
SetOutPath "C:\temp\NSIS_TEST\installdir"
SetOverwrite ifnewer
File "C:\temp\NSIS_TEST\sample01.txt"
SectionEnd


The sample file 'sample01.txt' is just a simple text file.
Here are the steps I used:[list=1][*]edit the sample01 file located in the folder with the NSI script. Added the text "old file". Closed and saved changes.[*]Compiled and ran the install. Checked to see that the sample file was installed to the proper directory.[*]edited the sample01 file (located in the same folder as my NSI script) and changed the text to "new file". Closed and saved.[*]Recompiled the script and ran the install.[*]Checked the sample01 file in my install directory. Found that it was the newer file as expected.[/list=1]

Hi Comperio.

Thanks for the reply -- for some reason I'm having difficulty reaching (only) the Winamp site. Hence the delay in responding.

I don't know how to check for an error. I watched the installer screen and it said nothing (neither "skipped" nor otherwise) for that file. How do I look for the error? I haven't been able to find it in the help file ...

Here's the code I use (some sections deleted for clarity). I have a sneaking suspicion that maybe due to nesting or something it's not working. But the build results that I posted in the original posting ought to indicate that the ifnewer attribute is reaching the right place ...

!macro Section_Compiler sdcode tdcode tname

SectionGroup "!${tname}" GRP_SEC_${sdcode}

!ifdef Pro
${Makefile_Files} "Pro Makefile Files" PRO_MAK ${SALVO_SRC_DIR} "ifnewer" "pro-makefile" ${sdcode} ${tdcode}
!endif

!ifdef Lite
Section -RemoveInc${sdcode}
FileWrite $UninstLog "$INSTDIR\${SUB_DIR}$\r$\n"
SectionEnd
Section -RemoveLib${sdcode}
FileWrite $UninstLog "$INSTDIR\${SUB_DIR}$\r$\n"
SectionEnd
Section -RemoveSrc${sdcode}
FileWrite $UninstLog "$INSTDIR\${SUB_DIR}$\r$\n"
SectionEnd
!endif


SectionGroupEnd

!macroend
!define Section_Compiler "!insertmacro Section_Compiler"


!macro Makefile_Files description ID subdir mode filename sdcode tdcode

Section "${description}" SEC_SALVO_${ID}_${sdcode}

SetOverwrite "${mode}"

${redef} SUB_DIR ${subdir}\Make\${tdcode}

!include "files\${sdcode}\salvo-files-${filename}.nsh"

SectionEnd

!macroend
!define Makefile_Files "!insertmacro Makefile_Files"

and it's invoked e.g. like this:
${Section_Compiler} KCARM   KCARM    "Keil ARM Development Tools -- CARM"
Thanks for your help -- I really need it on this one.

So I did some more testing -- ifnewer works in some places in my installer, but not in others. The Makefile example is one where it does not work, but here's one where it does (the file is named tut5.c). By "it works" I mean that I do see the new file in the installdir, and when the installer is running, I get an "extract: 100%" message.

Here's the code for a file that does end up being updated if it's newer in the installer:

!macro Section_Compiler sdcode tdcode tname

SectionGroup "!${tname}" GRP_SEC_${sdcode}

!ifdef Lite
${Example_Files} "Lite Example Files" LITE_EX ${SALVO_EX_DIR} "ifnewer" "lite-ex" ${sdcode} ${tdcode}
!endif

!ifdef Lite
Section -RemoveInc${sdcode}
FileWrite $UninstLog "$INSTDIR\${SUB_DIR}$\r$\n"
SectionEnd
Section -RemoveLib${sdcode}
FileWrite $UninstLog "$INSTDIR\${SUB_DIR}$\r$\n"
SectionEnd
Section -RemoveSrc${sdcode}
FileWrite $UninstLog "$INSTDIR\${SUB_DIR}$\r$\n"
SectionEnd
!endif


SectionGroupEnd

!macroend
!define Section_Compiler "!insertmacro Section_Compiler"


!macro Example_Files description ID subdir mode filename sdcode tdcode

Section "${description}" SEC_SALVO_${ID}_${sdcode}

SetOverwrite "${mode}"

${redef} SUB_DIR ${subdir}

!include "files\${sdcode}\salvo-files-${filename}.nsh"

SectionEnd

!macroend
!define Example_Files "!insertmacro Example_Files"
And here are the files that actually hold the source files in question: tut5.c
${SetOutPath}    "$INSTDIR\${SUB_DIR}\Luminary_LM3S1XX\Luminary_DK-LM3S1XX\RVMDK\Tut\Tut5"
${File} "${FILES_DIR}\${SUB_DIR}\" "Luminary_LM3S1XX\Luminary_DK-LM3S1XX\RVMDK\Tut\Tut5\tut5.c"

and Makefile:
${SetOutPath} "$INSTDIR\${SUB_DIR}"

; Compiler-specific Makefiles
${File} "${FILES_DIR}\${SUB_DIR}\" "Makefile"
Now I see the pattern -- those files that do work with ifnewer have a "more explicit" argument to SetOutPath -- i.e. the argument is not just variables. Where the argument to SetOutPath is only variables (which is where I need ifnewer to work most desperately), ifnewer doesn't work. Can you reproduce this problem in your example with a var argument to SetOutPath?

Thanks,

hmmm.. mine is still OK. But, I'm still a a bit confused about your script. Look at these lines of code:

${SetOutPath} "$INSTDIR\${SUB_DIR}"

; Compiler-specific Makefiles
${File} "${FILES_DIR}\${SUB_DIR}\" "Makefile"
The curly braces indicate either compile-time constants (using !define) or macro parameters. Since those lines of code are not in a macro (at least not that I can see), I assume they must be !defines. If so, that means that "${FILES_DIR}\${SUB_DIR}" can only be referencing compile-time variables which cannot change at runtime. (Did you perhaps mean to use "$FILES_DIR\$SUB_DIR\" instead?)

I may just be missing the big picture. Perhaps it might help if you could attach a complete example script that includes all the macros and defines. (Sorry for not being much help.)

Sorry -- I should have said that the final files in my example that reference tut5.c and Makefile are the *.nsh files that are included in the Example_Files and Makefile_Files macros ... therefore they are in a macro.

E.g.

!include "files\${sdcode}\salvo-files-${filename}.nsh"
means that this line in the Example_Files macro is replaced with
${SetOutPath}    "$INSTDIR\${SUB_DIR}\Luminary_LM3S1XX\Luminary_DK-LM3S1XX\RVMDK\Tut\Tut5"
${File} "${FILES_DIR}\${SUB_DIR}\" "Luminary_LM3S1XX\Luminary_DK-LM3S1XX\RVMDK\Tut\Tut5\tut5.c"
at compile time.

SUB_DIR, FILES_DIR, etc. are in fact defined constants.

There are so many files involved (this NSIS installer supports a whole bunch of different configurations -- all similar in nature, just with different files, all driven by different !defines depending on what we're building) that I don't think anything I can attach will be complete. If it's incomplete but includes all the associated files, will it be of use to you?

To be honest I'm not sure I fully understand the nuances of the compile-time and run-time variables. But the files are always installed to the right place, so I think my overall configuration is roughly correct. That's why I don't understand why ifnewer is failing me.

Does the fact that these lines are in a macro change things / mean that I'm doing something wrong with ifnewer?

So the net result (at least, mu intended result) is

!macro Example_Files description  ID subdir mode filename sdcode tdcode

Section "${description}" SEC_SALVO_${ID}_${sdcode}

SetOverwrite "${mode}"

${redef} SUB_DIR ${subdir}

${SetOutPath} "$INSTDIR\${SUB_DIR}\Luminary_LM3S1XX\Luminary_DK-LM3S1XX\RVMDK\Tut\Tut5"
${File} "${FILES_DIR}\${SUB_DIR}\" "Luminary_LM3S1XX\Luminary_DK-LM3S1XX\RVMDK\Tut\Tut5\tut5.c"

SectionEnd

!macroend
!define Example_Files "!insertmacro Example_Files"

I PM'd you re the files ...