0

-when writing the file to the cifs share from linux as root using python 2.7 shutil, no issue

-when writing the file manually using cp as a normal user, no issues

-when using python shutil.copy or copy2 as a normal user:

File "/usr/lib64/python2.7/shutil.py", line 120, in copy
copymode(src, dst)
File "/usr/lib64/python2.7/shutil.py", line 91, in copymode
os.chmod(dst, mode)
OSError: [Errno 1] Operation not permitted: '/mnt/RW_H-drive/file.csv
Arno
  • 307
  • 1
  • 4
  • 14
  • There's a bit hackish similar solution already on SO: http://stackoverflow.com/a/20022708/478237 – hruske Feb 28 '16 at 00:16
  • I've tried "del os.chmod" right after importing os and it doesn't change anything. Even if it had solved it though it would have been nice to know why it happens as a normal user and not as the root user. Actually this problem didn't occur on Debian testing, I'm only seeing it on CentOS7 – Arno Feb 28 '16 at 18:43

1 Answers1

1

I was wrong about Debian vs CentOS in the comment above, the Debian system drive died and I'm running my jobs on an enterprise box where the only possibilities are CentOS or SUSE so I can't compare /etc/fstab files. I was trying to mount the share using dir_mode=0777,file_mode=0777 without the uid=xxxx. I don't understand why but when you specify dir_mode and file_mode you get the permissions you expect and can write files to the share manually but using shutil fails with the error above. If you remove dir_mode and file_mode and use user uid=xxxx where xxxx is the user ID of any locally recognozised user (Local,LDAP or NIS) then permissions work as expected manually (cp or touch command etc) and also via python with shutil. I may have had the same issue with Debian when I first setup the fstab file that's why I had this little bell telling me to try uid, nothing else. Bizare thing is that the UID of the user in fstab and the cifs user are unrelated as far as I recall, they don't even have to have the same name. Also both mount lines work when you change files on the share as root user.

Example:

//nasx/sharex/ /mnt/RW_H-drive/   cifs    credentials=/root/smbcredentials,_netdev,uid=4321       0 0

Rather than:

//nasx/sharex/ /mnt/RW_H-drive/   cifs    credentials=/root/smbcredentials,_netdev,file_mode=0777,dir_mode=0777       0 0
Arno
  • 307
  • 1
  • 4
  • 14