Tcl 命令glob:type
这是我的命令:Tcl 命令glob:type,tcl,Tcl,这是我的命令: foreach fic [glob -nocomplain -dir $dir -types {f d r} *] { set infofile [list [file tail $fic] [file mtime $fic] [file atime $fic]] # ... } 只有我有一个错误:无法读取目录“/Users/…”权限被拒绝… 我的解决方案是添加以下命令:文件可读 foreach fic [glob -nocomplain -dir $dir -
foreach fic [glob -nocomplain -dir $dir -types {f d r} *] {
set infofile [list [file tail $fic] [file mtime $fic] [file atime $fic]]
# ...
}
只有我有一个错误:无法读取目录“/Users/…”权限被拒绝…我的解决方案是添加以下命令:
文件可读
foreach fic [glob -nocomplain -dir $dir -types {f d} *] {
if {![file readable $fic]} continue
set infofile [list [file tail $fic] [file mtime $fic] [file atime $fic]]
# ...
}
我认为当我添加
r
-类型时,这种错误没有出现。这是对文档的误解?Windows上的权限非常复杂,以至于您只能在成功打开文件进行读取后立即确定您有权读取该文件。
glob
和file readable
的指示不明确。在其他操作系统上就是这种情况,并且在任何情况下都存在竞争条件:用户可以在检查文件可读性
和调用其他操作之间更改权限。因此,虽然您可以使用glob-typer
,但不应该依赖它。这根本不能保证是正确的
解决这个问题的办法是什么?正确处理来自调用的错误
foreach fic [glob -nocomplain -dir $dir -types {f d r} *] {
try {
# More efficient than calling [file mtime] and [file atime] separately
file stat $fic data
} on error {} {
# Couldn't actually handle the file. Ignore
continue
}
set infofile [list [file tail $fic] $data(mtime) $data(atime)]
# ...
}
您在哪个平台上运行?@Brad Lanam Mac&Windows我想我们需要知道发生故障的文件/目录及其父目录的确切权限。我认为类型是条件的OR(“文件”或“目录”或“可读”)。此外,Windows上的访问控制权限非常复杂-有些方面我不了解,但至少我知道我不了解-因此最好只处理
open
可能失败的事实。glob
中的过滤是为了效率,而不是最终决定……r
有用吗?实际上,我认为r
没有那么有用。Windows使用访问控制列表,Linux可能有访问控制列表,而r
不适用于这些列表。谢谢@Brad Lanam,我也相信这一点