计算相对文件的父文件
因此,假设一个相对 URI
../file.ext
父级是
../
或
../../file.ext
如果是第一个,那么父级是什么
../
,它是第二个,如果重复调用假设的 getParent 方法,什么会终止潜在的无限循环?
So assuming a relative URI
../file.ext
Would the parent be
../
or
../../file.ext
If its the first, then what's the parent of
../
and it's the second, what would terminate a potentially infinite cycle if one were to repeatedly call a hypothetical getParent method upon it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定一个“当前目录”,
然后
../file.ext
将是,并且
../../file.ext
将被给定一个
getParent()
函数,当它到达文件系统的顶层时它必须停止。通过查看.
和..
的 inode 编号来检查这一点很简单。如果它们匹配,则您位于树的顶部。根据定义,在树的顶部执行“..”只会再次返回树的顶部。Given a "current directory" of
then
../file.ext
will beand
../../file.ext
will beGiven a
getParent()
function, it'd have to stop when it reaches the top level of the filesystem. That's trivial to check for by looking at the inode numbers of.
and..
. If they match, you're at the top of the tree. By definition, doing '..' at the top of the tree will just return the top of the tree again.