Can't save file to samba share
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
And yet it also seems to break the hard link to the original file, which, if that's the order of operations, has me puzzled.safe_write tries to create a temp file , writes to it and then renames to the desired name so the error seems to be saying that the temp file did not get ccreated.
Yep. No problems editing or saving through Axis at all... But I was under the impression Axis just popped a gedit window, while Gmoccapy uses something more integrated-ish?Have you tried using Axis or some other GUI? The safe_write function is used there as well.
If you mean PROGRAM_PREFIX, then yes, that's pointing at a directory on the share - but that doesn't (and seemingly shouldn't) matter. If I navigate to work with a local file, it's fine. Navigate to somewhere else on the share, and it breaks again.Or perhaps look at the ngc path in the gmoccapy ini files,
Figures.the error mesaage is rather typically useless as it doesn't give values for the parameters.
Ugh... I'm at least half a decade out from my coding days, and python was never one of my stronger languages to begin with. I may have to just give up and pop a terminal window with vi when I need to edit something.You might have to resort to the usual scripted language crutch of adding print statements to glade_vcp/hal_sourceview.py (linuxcnc/lib/python/gladevcp/hal_sourceview.py)
Or maybe I'll feel braver tomorrow.
And at least I've got somewhere to start poking.
Thanks,
-Bats
Please Log in or Create an account to join the conversation.
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
def safe_write(filename, data, mode=0o644):
import os, tempfile
fd, fn = tempfile.mkstemp(dir=os.path.dirname(filename), prefix=os.path.basename(filename))
try:
os.write(fd, data)
os.close(fd)
fd = None
os.rename(fn, filename)
os.chmod(filename, mode)
finally:
if fd is not None:
os.close(fd)
if os.path.isfile(fn):
os.unlink(fn)
It looks like the problem has nothing to do with creating the file... it's the chmod that kills it. Trying to chmod a file on a root-owned smb share as a non-root user gives "Operation not permitted" (and just silently fails when root tries it).
The question is, where do I go from here?
Just commenting out the chmod seems to make things work (the only apparent difference being that the files in local - permission-aware - filesystems end up as rw/-/- instead of rw/r/r), but that sets me up for trouble if an update comes along & breaks my "fix", and does nothing to resolve the issue for anyone else who finds themselves in the same mess.
Would it possible (or advisable) to just silently fail if the chmod fails, instead of throwing a tantrum? Does python allow nested try/catch blocks like that?
And should there be more checking done before unlinking (potentially deleting) the original file at the end, if this is going to be called "safe_write()"?
Any thoughts?
Or is there someone more qualified (read: even slightly qualified) that I can pass this off to?
-Bats
Please Log in or Create an account to join the conversation.
- gerritv
- Offline
- Senior Member
- Posts: 71
- Thank you received: 16
Perhaps setting Samba up using force user/group will help resolve it? www.thegeekdiary.com/how-to-force-user-g...es-on-a-samba-share/
(I presently have no way to try this but I will need this to work once I get set up, hence my interest)
Please Log in or Create an account to join the conversation.
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
That bothers me a bit too (although I suppose technically the files aren't root, just the share is mounted by root) - although it seemed to be the default I ended up with when setting the box up (up until I started trying to migrate to linuxCNC, I'd been away from linux for nearly as long as from coding, and I'm discovering it's absolutely nothing at all like riding a bicycle). My gut feeling, though, is that the problem is chmod'ing files on samba shares in general, rather than the owner of said shares. The fact that even root can't do a chmod (it just fails more quietly) would seem to hint in that direction.Maybe the real problem is that hte files are root in the first place?
Yeah... looks like it was an easy bandaid at the time, but now it's getting infected. Ew.This link references why the chmod was added but seems to not quite do what is needed. github.com/LinuxCNC/linuxcnc/issues/82
(not that I wouldn't have been inclined to do exactly the same thing)
I'll have to spend more timePerhaps setting Samba up using force user/group will help resolve it? www.thegeekdiary.com/how-to-force-user-g...es-on-a-samba-share/
(I presently have no way to try this but I will need this to work once I get set up, hence my interest)
-Bats
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
- Posts: 23563
- Thank you received: 4859
Years ago I found that the only way to make it work was to go via the "gvfs" folder where Linux mounts Samba shares.
Please Log in or Create an account to join the conversation.
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
I'm using gmoccapy's internal browser & going straight to /media/[share]/[path], where fstab mounts the share. Is there an alternative?How are you navigating to the samba share?
I didn't even realize Xfce used gvfs... Although I suppose Thunar must have something of the sort, since it seems to have its own private mounts that I could never find from the command line.Years ago I found that the only way to make it work was to go via the "gvfs" folder where Linux mounts Samba shares.
-Bats
Please Log in or Create an account to join the conversation.
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
Saving a new file to a share mounted this way (at least as long as the share owner is the same user linuxcnc is running as - I haven't tried any other scenarios) works without an error (yay!)... but trying to save to the existing file still complains - although this time it's the os.rename() that it dies on, instead of os.chmod(), and I'm not sure why.
Still digging.
-Bats
[edit: it should be noted that bats are not known for their burrowing prowess]
Please Log in or Create an account to join the conversation.
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
Also, I'd made some incorrect assumptions earlier about what the os.unlink was unlinking (and some possibly disparaging & probably unwarranted remarks about the "safety" of safe_write). It looks like that's just a cleanup of the temp file - so something else apparently causes the delinking of the original file. I don't understand that bit, either.
-Bats
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
- Posts: 23563
- Thank you received: 4859
[edit: it should be noted that bats are not known for their burrowing prowess
www.batcon.org/resources/media-education...zine/bat_article/228
Please Log in or Create an account to join the conversation.
- Bats
- Topic Author
- Offline
- Senior Member
- Posts: 55
- Thank you received: 7
That's uncle Henry. Should've known someone would bring up his branch of the family. We don't discuss them. Nesting in rotten logs? Filthy! And that whole "walking" thing is just plain undignified.
www.batcon.org/resources/media-education...zine/bat_article/228[edit: it should be noted that bats are not known for their burrowing prowess
But, while we're talking about digging anyhow... On a whim/following a lead, I decided to try replacing os.rename() with shutil.move(), annnnd...
...that didn't work either.
One possible workaround - although I couldn't find anything in the docs... I know Axis is supposed to be able to use vi - Is there any way to use an alternative editor with Gmoccapy?
This time it looks like it's specifically the destination file that it's having trouble finding - suggesting the removal of the hard link had already happened by the time the rename rolls around.
There's definitely something ugly happening between the rename process(es) and the samba share, but I'll be damned if I can figure out what it is. After spending the day struggling with this, I've pretty much hit a wall. I just don't know that I understand python or linux well enough at this point to make much progress. I'd already been forced to resort to trial and error, and now I've pretty much run out of errors to try.
Any other suggestions, ideas, or sheer random guessing?
[ edit: One possible workaround - although I couldn't find anything in the docs... I know Axis is supposed to be able to use vi - Is there any way to use an alternative editor with Gmoccapy? ]
-Bats
(not the digging kind, more's the pity)
Please Log in or Create an account to join the conversation.