开发者

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

开发者 https://www.devze.com 2022-12-08 23:17 出处:网络
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)?

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)?

I'm running Python 2.6.2 in OS X (10.6.1).

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 shar开发者_StackOverflowe.

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. There is many ways to go around permission checking if smb.conf isn't set correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号