简体   繁体   English

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

[英]Efficient inheritance of permission in folder/file system

I am writing a virtual file system in Java for a homework. 我正在用Java编写虚拟文件系统来做作业。 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? 与仅更新已更改节点的所有分支相比,我如何使它更有效率?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM