Calling external snap-installed apps with temp files

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Calling external snap-installed apps with temp files

Post by chennes »

I'm working on the OpenSCAD workbench, and the way we are sending data to OpenSCAD does not work if OpenSCAD is installed as a Snap package (or presumably if FreeCAD is installed as a snap package, though I have not tested that) -- we are currently using Python's temp directory functionality, but on Linux that end up being /tmp, which is unique to each snap so can't be used as a location to share information between apps. What is the preferred workaround for this? Is there a "standard" place for interprocess-communication-type temp files?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Calling external snap-installed apps with temp files

Post by chennes »

I want to bump this up to see if anyone else has an opinion on how I approach this, before I start coding. As near as I can tell, the only way I can accomplish this is to simply write the files to someplace like $HOME (they obviously get deleted later so the litter is temporary). I'd like a solution that will work when either FreeCAD or OpenSCAD is running as a flatpak/snap/whatever.

Pinging a couple of people who might know more about this than me!
keithsloan52 wrote: ping
NormandC wrote: ping
vejmarie wrote: ping
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Calling external snap-installed apps with temp files

Post by keithsloan52 »

I got the impression the whole point of snap installing was to place an application in a sand box with no ability to interact.
As such I don't think you should try and support and should just state that if people want to use OpenSCAD with FreeCAD then
they should not use a snap installation version of OpenSCAD or FreeCAD
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Calling external snap-installed apps with temp files

Post by chennes »

I think there are a number of reasons people install packages via Snap or Flatpak, but (anecdotally, I just chatted with a few people around the building), at least some people are doing it for ease and convenience, not for ultra-strict sandboxing. And I'm not a big fan of just saying that people who install FreeCAD via Snap can't use the OpenSCAD WB. Snap and flatpak provide specific mechanisms for users to allow home directory access, and both the OpenSCAD and the FreeCAD Snap have that plug enabled.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Calling external snap-installed apps with temp files

Post by sgrogan »

chennes wrote: Wed Sep 01, 2021 6:15 pm I think there are a number of reasons people install packages via Snap or Flatpak, but (anecdotally, I just chatted with a few people around the building), at least some people are doing it for ease and convenience, not for ultra-strict sandboxing. And I'm not a big fan of just saying that people who install FreeCAD via Snap can't use the OpenSCAD WB. Snap and flatpak provide specific mechanisms for users to allow home directory access, and both the OpenSCAD and the FreeCAD Snap have that plug enabled.
As a packager, this has been my experience as well. Users want an easy way to deal with FreeCAD, or other heavy packages, dependencies.
We add more and more stuff to the AppImage to make it easier.

To the original question, I would put the tmp files, that would be cleaned up, in .FreeCAD/ someplace. FreeCAD is writing them.
On Win %appdata%/FreeCAD/OpenSCAD/tmp?
"fight the good fight"
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Calling external snap-installed apps with temp files

Post by keithsloan52 »

sgrogan wrote: Wed Sep 01, 2021 6:40 pm To the original question, I would put the tmp files, that would be cleaned up, in .FreeCAD/ someplace. FreeCAD is writing them.
On Win %appdata%/FreeCAD/OpenSCAD/tmp?
And other operating systems?

Python has facilities for temp files https://docs.python.org/3/library/tempfile.html independent of OS and that I believe is what OpenSCAD uses.

If the python facilities do not work for snap installed applications, then I don't think people should be coming up with work arounds.
Either somebody fixes the python facility or it should be stated not supported.
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Calling external snap-installed apps with temp files

Post by sgrogan »

keithsloan52 wrote: Wed Sep 01, 2021 6:52 pm And other operating systems?

Code: Select all

~.FreeCAD/OpenSCAD/tmp
FreeCAD is already writing stuff, preferences ( for example user.cfg ).
keithsloan52 wrote: Wed Sep 01, 2021 6:52 pm If the python facilities do not work for snap installed applications, then I don't think people should be coming up with work arounds.
Either somebody fixes the python facility or it should be stated not supported.
I understand, but if both programs allow the interface? Maybe it is a feature, not a bug?
"fight the good fight"
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Calling external snap-installed apps with temp files

Post by chennes »

Python's temp stuff is not designed for interoperability, it just writes to the system temp location ("/tmp" on Linux, for example). We're sort of abusing it in this case to transmit data between apps, and Snap and Flatpak both explicitly do not share /tmp.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
adrianinsaval
Veteran
Posts: 5553
Joined: Thu Apr 05, 2018 5:15 pm

Re: Calling external snap-installed apps with temp files

Post by adrianinsaval »

sgrogan wrote: Wed Sep 01, 2021 7:16 pm

Code: Select all

~.FreeCAD/OpenSCAD/tmp
FreeCAD is already writing stuff, preferences ( for example user.cfg ).
in the snap too? Haven't ever used it but I remember the flatpak used a different directory for it's cfg files although it still used the same for everything else (workbench, macros, etc.)
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Calling external snap-installed apps with temp files

Post by keithsloan52 »

sgrogan wrote: Wed Sep 01, 2021 7:16 pm
keithsloan52 wrote: Wed Sep 01, 2021 6:52 pm And other operating systems?

Code: Select all

~.FreeCAD/OpenSCAD/tmp
FreeCAD is already writing stuff, preferences ( for example user.cfg ).
NOT on a MAC, but I guess one could use FreeCAD facilities to determine where preferences are stored.

Disagree that we are miss using the python facilities for temp files. Snap is restricting access to /tmp on an application basis for sandbox reasons.
Passing data in a file in another location is miss using snap, I would suggest. I stand by my opinion that it should just be unsupported until snap get their act together and supply some official mechanism for inter application transfer. I assume they don't allow applications to share /tmp because it is a security vulnerability, in that some third party could otherwise write a temp file in /tmp and then invoke the receiving application, hence passing data via a back door.
Post Reply