Question
· Apr 6, 2023

Using %Stream.FileCharacter to create and append to files - Permissions Issue

We have a function that was written for us that allows us to create text files for logging certain aspects to the OS using %Stream.FileCharacter. We had no issues with this until we moved from AIX to Red Hat.

Now it seems the 1st time the function is called, and the file is created the permissions seem to be correct on the file. But as soon as we attempt to write another line to the file using MoveToEnd() it seems the permissions are changed on the file. I have been able to narrow the issue down to the MoveToEnd() by calling the function from different users. 

When I initaly create the file via the function call I get the following permissions...

but as soon as a second call is made the permissions change to...

Here is the function code...

ClassMethod LogIt(pComponent As %String, pMsgIn As %String)

{

 set vDIR="/archive/logs/"

 set fs=##class(%Stream.FileCharacter).%New()

 set fs.Filename=vDIR_pComponent_".log"

 do fs.MoveToEnd()

 set vTM=$PIECE($ZDATETIME($HOROLOG)," ",2)

 //$ZTIME($PIECE($H,",",2),1)

 do fs.WriteLine(vTM_" : "_pMsgIn)

 do fs.%Save()

 set fs = "" // Close file

}

I have tried adding code to see if the file exists, then try an Open to open the file handle like we do in Perl but the permissions still seem to change.

Why when MoveToEnd() and Save is called a second time the permissions change? I can change the functionality just to use %File but it is not as efficent.

Thanks

Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2022.1 (Build 209U) Tue May 31 2022 12:13:24 EDT
Discussion (9)1
Log in or sign up to continue

We have gone through all the permission settings at the directory and user level. We do not believe it is an unmask issue as the file is ok when it is first created, but the subsequent writes cause the permissions to change. If it was an unmask issue wouldn't the file have the wrong permissions in the first place? And I confirmed its not a user issue as its been duplicated with the owner of the directory and others within the same group.

Instead of MoveToOpen is there a way to use Open the file and go to the end of the file to insert the data? I tried looking at %File but could not figure out now to append data to the end of the file I just kept overwriting data.

I tried the open also. But I did find a work around by resetting the ##class(%File).SetAttributes which is basically doing a chmod but at the ObjectScript level when creating/appending to the file. 

So what is %Stream really doing, is it just creating a new file based on what is in memory? Is it just reading the entire file into Memory so the IO is cut down and creating a new file from what is in Memory?