简体   繁体   English

如何使用Python将共享的网络文件设置为只读?

[英]How do you make a shared network file read-only using Python?

Using Python, what's the correct way to set a file to be read-only when the file is located on a network share (being served from a Windows 2003 Server)? 使用Python,当文件位于网络共享(由Windows 2003 Server提供)上时,将文件设置为只读的正确方法是什么?

I'm running Python 2.6.2 in OS X (10.6.1). 我正在OS X(10.6.1)中运行Python 2.6.2。

The following code throws an exception (as expected) when path is local, but os.chmod appears to have no effect when path points to a Windows share. 当路径是本地路径时,以下代码将引发异常(按预期),但是当路径指向Windows共享时, os.chmod似乎无效。

import os, stat

path = '/Volumes/Temp/test.txt'

# Create a test file.
open(path, 'w').close()

# Make the file read-only.
os.chmod(path, stat.S_IREAD)

# Try writing to it again. This should fail.
open(path, 'w').close()

I am pretty sure you must have the proper settings on your local SAMBA server (/etc/samba/smb.conf) to make this behave the way you intend. 我很确定您必须在本地SAMBA服务器(/etc/samba/smb.conf)上具有正确的设置,以使其按照您的预期方式运行。 There is many ways to go around permission checking if smb.conf isn't set correctly. 如果smb.conf设置不正确,有很多方法可以进行权限检查。

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

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