How can I specify file ownership when writing file output in SLAX?

By Elevate posted 08-07-2015 04:50


The preferred method for writing file output in SLAX is to use the <xsl:document> element. However, the <xsl:document> element does not provide any ability for you to specify file ownership or permissions, so your files are created with ownership "nobody" and permissions of "644".  Anyone can read the file, but only user "nobody" (or root) can modify or delete it.   


Suffice to say, littering your file system with files that can only be removed by user "root" is a bad practice.  Fortunately, there is a workaround for this:  initially create your file using the <file-put> RPC (which will allow you to specify ownership and permissions),  then subsequently overwrite that file with your "real" data using the <xsl:document> element.   Now you have a file that can modified or deleted by someone other than root.


For a complete write-up on this topic, see the page titled SLAX: Excerpt on the <xsl:document> Instruction Element


For an example of a simple convenience function to handle the initial housekeeping of setting proper ownership and permissions for files, see the page titled: How-To: Ensuring Proper Ownership and Permissions on File Creation in SLAX