mldvx4 has asked for the wisdom of the Perl Monks concerning the following question:
I plan to read the file permissions from an existing file, create a temporary file with the same permissions, rename the existing file to a backup name, and then give the temporary file the name of the original. In basic shell this would have been somewhat straight forward with mktemp(1), chmod(1), and mv(1) However, reading the manual page for File::Temp there seems to be no option to set the file permissions and it has a warning about working via the file handle instead of the file name:
For maximum security, endeavour always to avoid ever looking at, touching, or even imputing the existence of the filename. You do not know that that filename is connected to the same file as the handle you have, and attempts to check this can only trigger more race conditions. It's far more secure to use the filehandle alone and dispense with the filename altogether.
How can I use the file handle and still set the permissions and then rename the file after writing to it? Fcntl is mentioned but after looking at the manual page, it seems rather opaque.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using the file handle created by File::Temp to set specific file permissions
by dave_the_m (Monsignor) on Dec 10, 2021 at 17:54 UTC | |
by mldvx4 (Hermit) on Dec 11, 2021 at 06:04 UTC | |
|
Re: Using the file handle created by File::Temp to set specific file permissions
by choroba (Cardinal) on Dec 10, 2021 at 13:27 UTC | |
by mldvx4 (Hermit) on Dec 11, 2021 at 06:02 UTC | |
|
Re: Using the file handle created by File::Temp to set specific file permissions
by eyepopslikeamosquito (Archbishop) on Dec 11, 2021 at 07:25 UTC | |
by mldvx4 (Hermit) on Dec 11, 2021 at 08:37 UTC |