简体   繁体   English

在Subversion存储库中存储文件权限

[英]Storing file permissions in Subversion repository

How do you store file permissions in a repository? 如何在存储库中存储文件权限? A few files need to be read-only to stop a third party program from trashing it but after checking out of the repository they are set to read-write. 一些文件需要是只读的,以阻止第三方程序对其进行垃圾回收,但从存储库中签出后,它们将被设置为可读写。

I looked on google and found a blog post from 2005 that states that Subversion doesn't store file-permissions. 我在Google 上浏览后发现2005年博客文章指出Subversion不存储文件权限。 There are patches and hook-scripts listed (only one url still exists). 列出了补丁和挂钩脚本(仅存在一个URL)。 Three years later does Subversion still not store file permissions and are hooks the only way to go about this? 三年后,Subversion仍不存储文件许可权,而钩子是实现此目的的唯一方法吗? (I've never done hooks and rather use something that is native to Subversion.) (我从来没有做过钩子,而是使用了Subversion固有的东西。)

SVN does have the capability of storing metadata ( properties ) along with a file. SVN确实具有存储元数据( 属性 )和文件的功能。 The properties are basically just key/value pairs, however there are some special keys like the 'svn:executable', if this property exists for a file, Subversion will set the filesystem's executable bit for that file when checking the file out. 这些属性基本上只是键/值对,但是有一些特殊的键,例如'svn:executable',如果该属性存在于文件中,则Subversion会在检出文件时设置该文件的文件系统可执行位。 While I know this is not exactly what you are looking for it might just be enough (was for me). 虽然我知道这并不是您要找的东西,但可能就足够了(对我而言)。

There are other properties for line ending (svn:eol-style) and mime type(svn:mime-type). 行尾(svn:eol-style)和mime type(svn:mime-type)还有其他属性。

There's no native way to store file permissions in SVN. 没有本地方法可以在SVN中存储文件权限。

Both asvn and the patch from that blog post seem to be up (and hosted on the official SVN repository), and that's a good thing, but I don't think they will have such metadata handling in the core version any time soon. asvn博客文章中的补丁似乎都已启动(并托管在SVN官方存储库中),这是一件好事,但我认为它们不会很快在核心版本中进行此类元数据处理。

SVN has had the ability to handle symbolic links and executables specially for a long while, but neither work properly on Win32. SVN长期以来一直具有处理符号链接可执行文件的能力,但在Win32上均无法正常工作。 I wouldn't hold my breath for another such non-portable feature (though it wouldn't be too hard to implement on top of the already existing metadata system.) 我不会为另一个这样的不可移植的功能而屏住呼吸(尽管在已经存在的元数据系统之上实现起来并不难)。

I would consider writing a shell script to manually adjust file permissions, then putting it in the repository. 我会考虑编写一个Shell脚本来手动调整文件权限,然后将其放入存储库中。

One possible solution would be to write a script that you check in with the rest of your code and which is run as the first step of your build process. 一种可能的解决方案是编写一个脚本,将其与其余代码一起签入,并在构建过程的第一步中运行。

This script runs through your copy of the codebase and sets read permissions on certain files. 该脚本贯穿您的代码库副本,并设置对某些文件的读取权限。

Ideally the script would read the list of files from a simple input file. 理想情况下,脚本将从简单的输入文件中读取文件列表。 This would make it easy to maintain and easy for other developers to understand which files get marked as read-only. 这将使其易于维护,并使其他开发人员易于理解哪些文件被标记为只读。

Since this wasn't fully said in previous responses yet. 由于在先前的回复中尚未完全说明这一点。 I hate to resurrect zombied threads though. 我讨厌复活僵尸线程。

Since adding permission support for SVN would have to accommodate multiple OS's and permission types, NFS, POSIX, ARWED, and RACF 由于添加了对SVN的权限支持,因此必须容纳多种操作系统和权限类型,因此NFS,POSIX,ARWED和RACF

This would make SVN bloated, possibly clash with conflicting permission types like NFS and POSIX, or open up possible exploits/security vulnerabilities. 这将使SVN膨胀,可能与诸如NFS和POSIX之类的冲突权限类型发生冲突,或者公开可能的利用/安全漏洞。

There are a couple of workarounds. 有几种解决方法。 pre-commit, post-commit, start-commit are the more commonly used, and are a part of the Subversion system. Pre-commit,post-commit,start-commit是更常用的,并且是Subversion系统的一部分。 But will allow you to control the permissions with what ever programming language you like. 但是,您可以使用自己喜欢的任何编程语言来控制权限。

The system I implemented is what I call a packager, that validates the committed files of the working copy, then parses a metadata file, which lists out the default permissions desired for files/folders, and any changes to them you also desire. 我实现的系统就是我所说的打包程序,它首先验证工作副本的已提交文件,然后解析元数据文件,该元数据文件列出了文件/文件夹所需的默认权限,以及对它们的任何更改。

Owner, Group, Folders, Files
default: <user> www-user 750 640
/path/to/file: <user> non-www 770 770
/path/to/file2: <user> <user> 700 700

You can also expand upon this and allow things such as automated moving, renaming them, tagging revision by types, like alpha, beta, release candidate, release 您还可以对此进行扩展,并允许诸如自动移动,重命名它们,按类型(例如alpha,beta,候选发行版,发行版)标记修订等功能

As far as supporting clients to checkout your repository files with permissions attached to them. 就支持客户端签出具有附加权限的存储库文件而言。 You are better off looking into creating an installer of your package and offering that as a resource. 您最好考虑创建软件包的安装程序并将其作为资源提供。

Imagine people setting their repositories with an executable in it set with permissions of root:www-user 4777 想象一下,人们使用可执行文件设置其存储库,并在其中设置了root:www-user 4777的权限

This is the updated link for SVN patch which handles unix style file permissions correctly. 是SVN修补程序的更新链接,可正确处理Unix样式文件权限。 I have tested out on fedora12 and seems to work as expected: 我已经对fedora12进行了测试,并且似乎可以正常工作:

I just saved it /usr/bin/asvn and use asvn instead of svn command if i need permissions handled correctly. 我只保存了/ usr / bin / asvn,如果我需要正确处理权限,请使用asvn而不是svn命令。

Many answers have stated that svn does not store file permissions. 许多答案表明svn不存储文件权限。 This may be true, but I was able to solve a dll file without execute permissions problem simply by these steps: 这可能是正确的,但是通过以下步骤,我能够解决没有执行权限问题的dll文件:

  1. chmod 755 badpermission.dll chmod 755 badpermission.dll
  2. mv badpermission.dll ../ mv badpermission.dll ../
  3. svn update svn更新
  4. svn rm badpermission.dll svn rm badpermission.dll
  5. svn commit badpermission.dll -m "Remove dll to fix permissions" svn commit badpermission.dll -m“删除DLL修复权限”
  6. mv ../badpermission.dll . mv ../badpermission.dll。
  7. svn add badpermission.dll SVN添加badpermission.dll
  8. svn commit badpermission.dll -m "Add the dll back to fix permissions" svn commit badpermission.dll -m“重新添加dll以修复权限”
  9. rm badpermission.dll rm badpermission.dll
  10. svn update svn更新
  11. badpermission.dll comes back with execute permissions badpermission.dll带有执行权限

我建议使用mtree实用程序(默认情况下FreeBSD拥有它)生成权限映射,将其存储在存储库中,并且如上所述,运行一个脚本,该脚本将从映射中恢复适当的文件权限,这是该操作的第一步。构建过程。

@morechilli: @morechilli:

The asvn wrapper from my earlier post and the blog in the OP's post seems to do what you're suggesting. 我之前的帖子中的asvn包装器以及OP帖子中的博客似乎都在执行您的建议。 Though it stores the permissions in the corresponding files' repository properties as opposed to a single external file. 尽管它将权限存储在相应文件的存储库属性中,而不是单个外部文件。

Locking would not solve this problem. 锁定无法解决此问题。 Locking stops others from editing the file. 锁定会阻止其他人编辑文件。 This is a third party application which gets run as part of the build process that tries to write to a file - changing it - which breaks the build process. 这是第三方应用程序,它在构建过程中运行,试图写入文件(更改文件),这会破坏构建过程。 Therefore we need to stop the program from changing the file which is simply marking the file read-only. 因此,我们需要停止程序更改文件,而这只是将文件标记为只读。 We would like that information to be held in the repository and carried across checkins, branches, etc. 我们希望将这些信息保存在存储库中并在签入,分支等之间携带。

Graham, svn doesn't store permissions. Graham, svn不存储权限。 Your only option is to wrap your call to svn in a script. 唯一的选择是svn的调用包装在脚本中。 The script should call svn with its arguments, then set the permissions afterward. 该脚本应使用其参数调用svn ,然后再设置权限。 Depending on your environment, you might need to call your script svn and tweak your PATH to ensure it gets called. 根据您的环境,您可能需要调用脚本svn并调整PATH以确保其被调用。

I quite like morechilli's idea to have the list of files and permissions checked into the repository itself. 我非常喜欢morechilli的想法,即将文件列表和权限列表检入存储库本身。

We created a batch file to do this for us. 我们创建了一个批处理文件来为我们做这件事。 Would prefer actual support in subversion though... 宁愿在颠覆中提供实际支持,但...

考虑使用svn lock禁止其他人写入文件。

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

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