Can't save file to samba share

More
6 years 4 months ago #173155 by Bats
Replied by Bats on topic Can't save file to samba share
annnd....

It looks like "save the file using the original name" will not only fail to update, but will actually destroy (or at least somehow mangle) the original file. Check out how test4.ngc behaves when I try to cat it in this screencap:



(and no, surprising though it may be, the file actually doesn't contain the text "cat: test4.ngc: No such file or directory").

Also, check out that "0" in the links filed on the ls -l... That was a "1" before I tried saving, which could definitely account for cat's trouble... but I have no idea why gmoccapy's editor would've borked it like that, or even how a file with zero hard links still exists at all.

Curiouser and curiouser.

And I'm way out of my depth here.

-Bats

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #173158 by gerritv
Are you perhaps falling victim to Samba using SMB1 by default? Win10 turns that off (and it should be kept that way). This article might help change Samba config to use SMB2. www.cyberciti.biz/faq/how-to-configure-s...v1-on-linux-or-unix/
I have no direct experience with this combination yet, perhaps next week before I get to that stage with my set up.

Gerrit

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #173159 by Bats
Replied by Bats on topic Can't save file to samba share

gerritv wrote: Are you perhaps falling victim to Samba using SMB1 by default?

Possible, but unlikely. I think. Probably. Maybe.

As far as I can tell (and I'll admit, my brain's been feeling pretty mushy lately) that link is only related to the samba server, while my problem is client-side. I don't think I even have smbd installed on this box, and the trouble is all with files being hosted on Win7/Win8 boxes.

I'm also having trouble understanding why a difference in protocol would only impact Gmoccapy's editor... but I suppose it'd hardly be the strangest thing I'd ever seen.

-Bats

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #173161 by gerritv
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.
Have you tried using Axis or some other GUI? The safe_write function is used there as well. Or perhaps look at the ngc path in the gmoccapy ini files, the error mesaage is rather typically useless as it doesn't give values for the parameters. 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)

The file write mode for safe_write is 0x644

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #173166 by Bats
Replied by Bats on topic Can't save file to samba share

gerritv wrote: 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.

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.


Have you tried using Axis or some other GUI? The safe_write function is used there as well.

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?


Or perhaps look at the ngc path in the gmoccapy ini files,

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.


the error mesaage is rather typically useless as it doesn't give values for the parameters.

Figures.


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)

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.

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.

More
6 years 4 months ago #173213 by Bats
Replied by Bats on topic Can't save file to samba share
So here's the function in question (thanks for giving me the needed kick in the bats to go looking at it, gerritv - it was more straightforward than I feared):
Code:
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)
( from /usr/lib/python2.7/dist-packages/gladevcp/hal_sourceview.py )

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.

Moderators: newbynobi, HansU
Time to create page: 0.083 seconds
Powered by Kunena Forum