如何通过UID检查目录是否可写?
能否使用 File::Find::Rule 来确定给定 UID 是否可写入目录?
我使用了以下测试:
my $uid = 123; # or whatever...
my @subDirs = File::Find::Rule->permissions(isWriteable => 1, user => "$uid")->directory()->maxdepth(1)->in( $dir );
if (scalar @subDirs == 0) {
die "$dir is not writeable...";
}
die "$dir is writeable";
但它总是返回 $dir 是可写的,即使对于我知道受到限制的测试目录也是如此。
我可以对此测试进行哪些调整以使其发挥作用?
编辑
使用use File::Find::Rule qw(permissions)
导致脚本崩溃。我以前不需要在旧的 File::Find::Rule
操作中使用 permissions()
来指定此选项。
如果我按如下方式调整规则,事情就会正常进行。
在这里,我正在测试子目录列表中是否存在父目录:
my @subDirs = File::Find::Rule::Permissions->directory()->permissions(isWriteable => 1, user => "$uid")->maxdepth(1)->name(".")->in("$dir");
$dir
子目录的父目录是 .
并且该目录是否存在于列表中@subDirs
,它必须是可写的。
感谢 ikegami 推荐这个模块。
Can File::Find::Rule
be used to determine if a directory is writeable by a given UID?
I have used the following test:
my $uid = 123; # or whatever...
my @subDirs = File::Find::Rule->permissions(isWriteable => 1, user => "$uid")->directory()->maxdepth(1)->in( $dir );
if (scalar @subDirs == 0) {
die "$dir is not writeable...";
}
die "$dir is writeable";
But it always returns that the $dir
is writeable, even for test directories that I know are restricted.
What adjustments can I make to this test to make it work?
EDIT
Using use File::Find::Rule qw(permissions)
caused the script to crash. I have not ever needed to specify this option with previous usages of permissions()
in older File::Find::Rule
operations.
If I adjust the rule as follows, I get things working.
Here, I am testing for the presence of the parent directory in the subdirectory list:
my @subDirs = File::Find::Rule::Permissions->directory()->permissions(isWriteable => 1, user => "$uid")->maxdepth(1)->name(".")->in("$dir");
The parent directory of the subdirectories of $dir
is .
And if that directory exists in the list of @subDirs
, it must be writable.
Thanks to ikegami for suggesting this module.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里,我测试子目录列表中是否存在父目录:
$dir
的子目录的父目录是。
如果该目录存在于 < 列表中code>@subDirs,它必须是可写的。
Here, I test for the presence of the parent directory in the subdirectory list:
The parent directory of the subdirectories of
$dir
is.
If that directory exists in the list of
@subDirs
, it must be writable.