0

I am using the standard XML library that comes with Genero 4GL. I am trying to save the XML document to a specific directory based on a variable in a properties file. I can see that it is getting the correct path, AND I can verify that the permissions on the folders it is going to is 777 (it's Linux based). However, I keep getting an "unable to open resource for writing" error when I get to the save call.

try
  let doc = xml.domDocument.create()
  call doc.setXmlStandalone(true)
  let report_node = doc.createDocumentFragment()

  call xml.Serializer.VariableToDom(rpt_rec[1], report_node)
  call doc.appendDocumentNode(report_node)
  call doc.normalize()
  call doc.setFeature("format-pretty-print", true)
  call doc.save(xml_file)

  return true
catch
  for i=1 to doc.getErrorsCount()
    display "[", i, "] ", status, " ", doc.getErrorDescription(i)
  end for

  return false
end try

I haven't been able to find anything in the Genero documentation as to why I am getting this error. The only thing I know is that if I just save the XML to the /tmp directory, it works. But if I try to save anywhere else, it doesn't.

Can anyone please provide some insight as to why I can only save my XML document to the /tmp directory even though the permissions on the folder I want it to go to are correct? Thanks.

snowfi6916
  • 697
  • 4
  • 9
  • 21

1 Answers1

0

Your description of the issue points at O/S permissions. I know you say you have checked permissions but perhaps add some debug code such as ...

DISPLAY xml_file
DISPLAY os.Path.writable(xml_file)
DISPLAY os.Path.writable(os.Path.dirName(xml_file))
DISPLAy os.Path.rwx(xml_file)
DISPLAY os.Path.rwx(os.Path.dirName(xml_file))

... to verify that the code is where you think it is.

There was one case in our knowledge base dating from 2017 where a customer reported a similar issue. Unfortunately they did not follow up with a small https://stackoverflow.com/help/minimal-reproducible-example that allowed us to reproduce but at the time we questioned the format of the URI in their example (it was to a Windows network drive from their Linux server) and also that they were writing to the same file they were reading.

fourjs.reuben
  • 286
  • 3
  • 3
  • Hi Reuben. I added the debug code you suggested and got the following results: 1) `DISPLAY xml_file` returned the correct path where I want the XML file to be saved. 2) `DISPLAY os.Path.writable(xml_file)` returned 0. 3) `DISPLAY os.Path.writable(os.Path.dirName(xml_file)` returned 1 The `rwx` calls returned -1 and 511 respectively. So for some reason, the XML file itself is not writable if I do anything other than `/tmp`, but the directory itself IS writable is what I'm gathering from the output. – snowfi6916 Mar 22 '22 at 12:49
  • If I change the directory to `/tmp`, the `os.Path.writable` returns 1, and `os.Path.rwx` returns 438. – snowfi6916 Mar 22 '22 at 12:54
  • I probably should have had os.Path.exists(xml_file) in the debug mix as well. Is your variable simply a filename and not a URL? I do get the error you see if I have "file:///foo.xml" instead of "foo.xml" – fourjs.reuben Mar 22 '22 at 22:40
  • Hi Reuben. `os.Path.exists(xml_file)` returns 0. This is not correct, as I can see the directory in the system. Also, the variable is just a filename with a path: `/u/mainFolder/xmlFolder/xmlFile.xml`. And like I said, I can see that folder in my system, so `os.Path.exists` returning 0 is wrong. – snowfi6916 Mar 23 '22 at 13:16
  • One more thing. If I do `/u/mainFolder/xmlFolder` for the `os.Path.exists` call, THAT returns 1. If I add the `xmlFile.xml` to it, it returns 0. – snowfi6916 Mar 23 '22 at 13:24
  • Hi Reuben. I'm still having this issue. Is there anything else I can try? – snowfi6916 Mar 31 '22 at 13:02
  • Sometimes using truss or similar may yield a result. If the issue still persists, then raise a formal support call. As I said at beginning, fact that someone raised a similar issue back in 2017 suggests there maybe some obscure condition that lead to the error you report. – fourjs.reuben May 02 '22 at 23:45