开发者

How do I change the default file permissions in Storable?

Can I somehow change the default file permiss开发者_StackOverflowions when using the store function from Storable?


There are a couple of different approaches to this. (Of course there are; it's Perl :-) )

First option: use sysopen() to create the file with the specified permissions, then use store_fd() and fd_retrieve(). See also the Perl open() tutorial, particularly the "Permissions a la mode" section.

Second option: use umask() to limit the file permissions. Don't forget to set it back to its original value if you're working with multiple files.

Third option: use chmod() to set the file permissions manually on a pre-existing file.

The first option is conceptually better because it allows the user to tighten permissions further by controlling the umask themselves. (Try help umask at a shell prompt. The umask set there applies to all programs run from the shell. Again, see perlopentut.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜