文件夹/文件系统权限的高效继承

发布于 2025-01-08 16:16:42 字数 235 浏览 0 评论 0原文

我正在用 Java 编写一个虚拟文件系统作为作业。我设计的权限规则非常简单,只包含三个权限:读取、更改、删​​除。由于文件系统树已扩展,因此用户可以选择任何级别的任何文件/文件夹。当用户更改文件夹的权限时,该文件夹中的所有文件/文件夹也应继承更改并更新自己的权限。但是,当树变得非常深时,更新下面的所有节点可能会效率低下,例如:在子节点的权限更改后,父节点的权限也发生更改,那么似乎可能会产生一些多余的工作。如何才能使其比仅更新已更改节点的所有分支更有效?

I am writing a virtual file system in Java for a homework. I design the permission rules very simple which only consist of three permissions: Read, Change, Delete. Since the file system tree is expanded so that user can select any files/folders in any level. When user change the permission of a folder, all files/folders in this folder should also inherit the changes and update their own permissions. But updating all nodes under can be inefficient when tree becomes really deep or for example: father node's permission is changed after son node's permission has been changed, then seems like there may incur some redundant works. How can I make it more efficient than just updating all branches of that changed node?

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

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

发布评论

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

评论(1

橘虞初梦 2025-01-15 16:16:42

在进行权限更新的成本和计算对象的有效权限的成本之间存在权衡。

例如,您可以通过存储权限和权限时间戳来加快权限更新速度。然后,通过查看节点及其所有祖先的权限/时间戳对来计算节点的有效权限 - 具有最新时间戳的优先。当然,这意味着计算节点的有效权限会更慢。

(然后,您可以使用目录的权限/时间戳对的内存中 LRU 缓存来更快地进行有效权限计算。)

There is a trade-off between the cost of doing the permissions update, and the the cost of calculating the effective permissions of an object.

For instance, you could make permission update faster by storing the permissions and a permission timestamp. Then you calculate the effective permissions of a node by looking at the permission / timestamp pair of the node and all of its ancestors - the one with the newest timestamp takes precedence. Of course, this means that calculating a node's effective permissions is slower.

(You could then make the effective permission calculation faster with an in-memory LRU cache of the permission / timestamp pairs for directories.)

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