如何更改可存储中的默认文件权限?

发布于 2024-10-04 09:41:13 字数 119 浏览 0 评论 0原文

使用 Storablestore 函数时,我可以以某种方式更改默认文件权限吗>?

Can I somehow change the default file permissions when using the store function from Storable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情未る 2024-10-11 09:41:13

对此有几种不同的方法。 (当然有;它是 Perl :-) )

第一个选项:使用 sysopen() 创建具有指定权限的文件,然后使用 store_fd()fd_retrieve()。另请参阅 Perl open() 教程,特别是“Permissions时尚”部分。

第二种选择:使用 umask() 来限制文件权限。如果您正在处理多个文件,请不要忘记将其设置回原始值。

第三种选择:使用 chmod() 来对预先存在的文件手动设置文件权限。

第一个选项在概念上更好,因为它允许用户通过自己控制 umask 来进一步收紧权限。 (在 shell 提示符处尝试 help umask。那里设置的 umask 适用于从 shell 运行的所有程序。再次参见 perlopentut。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文