Archive: File owner & permission


File owner & permission
Hello forum,

I have got a big problem with NSIS.

I use AdvReplaceInFile to replace some strings in my file I would like to change.
This works great. After all actions I set my file permissions with AccessControll Plugin, but the permissions and the file owner will not be set correctly.

I suppose so that the temporary file (that will be copied over original) that will be created with AdvReplaceInFile does not get the file permissions from AccessControll Plugin.

Is there any workaround or something I does not know ?!


Did you try setting the privileges after calling AdvReplaceInFile?


Hello kichik,

yes of course, first I replace in some files, after that I
change the file privileges.

The strange thing is that all files which were not substituted with some new text have the privileges I set. All with replaced text contain privileges like new created files within this account installer run in.

Greetings,

Wolfgang.


Well, usually what this kind of functions do is create a new file and write the new data into it. You could either change that script to create the file in the correct folder, or do the replacement in another file and later manually copy the contents into the old file.


Hello kichik,

I think this will do what I want, but isn`t it a little bit strange that the
AccessControl Plugin will not change new file attributes which are (should ?) created befor changing attributes ?

This seems to be a bug for me. :cry:
Looks like NSIS will copy the temporary files at the end of the installer
over my orginal ? :weird:

The question for me is, if this is an NSIS or an Plugin problem.

Greetings,

Wolfgang.


Looks like NSIS will copy the temporary files at the end of the installer over my orginal?
As I said, that's what those replacement scripts usually do. It's a problem with the script.

Hello kichik,

yes that is right, but the replacement script calls the rename statement within his replace function. Shouldn`t NSIS rename the file when this statment is called !? For me looks this like NSIS renaming all files at the end of the install time. But not at this time where rename is called !? I am a little bit confused now.


Rename renames immediately. The problem is that the temporary files it renames is either created in the temporary folder and therefore gets a different set of privileges, or the destination file has privileges different than even those of the folder that contains it.


Hi,

but shouldn`t work set file privileges as expected in your case ?!
I am right that renames copy the temp file to my $INSTDIR ?

Flow Diagram:

OriginalFile -> ReplaceFunctionCall() -> CreateTempFile ->
WriteReplacementInTempFile -> DeleteOriginal -> RenameTempFile ->
DeleteTempFile -> setFilePrivileges

NSIS Script:

...
; Original File for String Replace.

File "/oname=$INSTDIR\filename.txt" ".\filename.txt"

; Starting String Replacment.

!insertmacro AdvReplaceInFile "$INSTDIR\filename.txt" "abc" "xyz" all all


; User is existing in Windows XP Environment.
; This should now change my file privileges on my file which
; should be the file in which the strings are replaced,
; But it is not.

AccessControl::GrantOnFile "$INSTDIR\filename.txt" "Apache" "FullAccess"
AccessControl::SetFileOwner "$INSTDIR\filename.txt" "Apache"
AccessControl::SetFileGroup "$INSTDIR\filename.txt" "ApacheGroup"
...

This seems to be a bug for me.
Is there any workaround instead of truncate my original file and copy content of temp file ?!

Greetings,

Wolfgang.


I haven't looked into AdvReplaceInFile, but your flow diagram describes what most of those functions do, so it's probably right. As I said, you have two options. The first, and simpler, is changing that function so it'd create the temporary file in $INSTDIR and not $TEMP. This way, it'll get the attributes of $INSTDIR automatically. Your second option is not to rename at all and manually copy the contents of the file.

However, if all that is wrong is the file owner, you might have a problem with that AccessControl call and all you need to do is fix it. Make sure that call works on the file itself, without calling AdvReplaceInFile.