2009-10-13 85 views
0

使用Python,當文件位於網絡共享位置(從Windows 2003服務器提供)時,將文件設置爲只讀的正確方法是什麼?如何使用Python以只讀方式創建共享網絡文件?

我在OS X(10.6.1)中運行Python 2.6.2。

當路徑是本地路徑時,以下代碼會引發異常(如預期的那樣),但當路徑指向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() 
+0

如果您從OS X命令窗口嘗試chmod,它工作嗎?否則,這可能是聯網互操作的限制。 – 2009-10-13 16:59:16

回答

0

我敢肯定,你必須在本地SAMBA服務器上的適當設置(/etc/samba/smb.conf中),使這個行爲你想讓你的方式。如果smb.conf設置不正確,有許多方法可以繞過權限檢查。