编辑文件时保留samba共享的文件权限 [英] preserving file permissions for samba shares when file is edited

查看:412
本文介绍了编辑文件时保留samba共享的文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的代码库已从Git存储库检出到我的Linux机器上.由于我们的生产代码被编写为可以在Linux上部署,因此我在Linux机器上进行了所有测试,但希望将Windows用于日常使用,包括代码编辑/创作.

The code bases I work with are checked out from Git repositories onto my Linux machine. Since our production code is written to be deployed on Linux, I do all the testing on my Linux machine but like to use Windows for everyday usage, including code editing/authoring.

为此,我创建了文件夹(我的主文件夹)的 Samba共享,将代码检出到该文件夹​​中,如下所示:

For that purpose, I have created a Samba share of the folder (my home folder) where I checkout the code to, like this:

[wgrover]
    path = /home/wgrover
    available = yes
    valid users = wgrover
    read only = no
    browsable = yes
    public = yes
    writable = yes

但是,当我从Windows中的samba共享\\linux-box\wgrover中编辑文件时, Linux中的文件许可权会不断更改为755,即使在编辑前为644也是如此.

However, when I edit a file from the samba share \\linux-box\wgrover in Windows, the file permission in Linux keeps changing to 755 even though it was 644 before editing.

这样一直显示在我的git diff中:

This keeps showing up in my git diff like this:

diff --git a/debian/maggie.nginx.conf b/debian/maggie.nginx.conf
old mode 100644
new mode 100755
index 7cda506..7eab574

可以在smb.conf中设置create mask,但这也不会保留"原始文件权限.我可以通过在.gitconfig中设置fileMode = false来忽略git中的文件模式更改,但这也可以忽略该问题.

It is possible to set a create mask in smb.conf but that will also not "preserve" the original file permissions. I can ignore file mode changes in git by setting fileMode = false in .gitconfig but that also ignores the problem.

从Linux修改文件权限后,是否可以保留文件权限?

Is there any way to preserve the file permissions when they are modified from linux?

推荐答案

最终可以弄清楚权限为何更改.混淆来自map archive = yes设置,它是Samba中的默认值.设置map archive = no后,所有者执行位开始以我预期的方式运行.

Could finally figure out why permission was changing. The confusion arose from the map archive = yes setting being the default value in Samba. After setting map archive = no, the owner execute bit started behaving like I expected it to behave.

通过阅读以下文档来找到答案: http://www. samba.org/samba/docs/using_samba/ch08.html 中的 MS-DOS和Unix上的文件权限和属性部分.它清楚地提到了这种副作用:

Found the answer by reading the documentation over here: http://www.samba.org/samba/docs/using_samba/ch08.html in the File Permissions and Attributes on MS-DOS and Unix section. It clearly mentions this side effect:

因此,Samba磁盘共享中文件上存在的三个Unix可执行位没有任何用处.但是,DOS文件具有自己的属性,当它们存储在Unix环境中时需要保留:存档,系统和隐藏位.如果有指示,Samba可以通过在Unix端重用文件的可执行权限位来保留这些位.但是,映射这些位会带来不幸的副作用:如果Windows用户将文件存储在Samba共享中,而您在Unix上使用ls -al命令查看该文件,则某些可执行位将不代表您的意愿.希望他们如此.

Consequently, there is no use for any of the three Unix executable bits that are present on a file in a Samba disk share. DOS files, however, have their own attributes that need to be preserved when they are stored in a Unix environment: the archive, system, and hidden bits. Samba can preserve these bits by reusing the executable permission bits of the file on the Unix side--if it is instructed to do so. Mapping these bits, however, has an unfortunate side effect: if a Windows user stores a file in a Samba share, and you view it on Unix with the ls -al command, some of the executable bits won't mean what you'd expect them to.

但是,它也提到了这一点:

However, it also mentions this:

我们应该警告您,map archive选项的默认值为yes,而其他两个选项的默认值为no.这是因为,如果未正确存储DOS和Windows文件的存档位,则许多程序将无法正常运行.但是,系统属性和隐藏属性对于程序的运行而言并不重要,而是由管理员自行决定.

We should warn you that the default value of the map archive option is yes, while the other two options have a default value of no. This is because many programs do not work properly if the archive bit is not stored correctly for DOS and Windows files. The system and hidden attributes, however, are not critical for a program's operation and are left to the discretion of the administrator.

您还可以在此处了解有关存档位的更多信息: http://en.wikipedia.org/wiki/Archive_bit

You can also read more about the archive bit over here: http://en.wikipedia.org/wiki/Archive_bit

这篇关于编辑文件时保留samba共享的文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆