Output listing from PEngine app to file in quick load format?

I’m using: SWI-Prolog version 8.0.2 on Ubuntu Linux 18.04.

My user data strategy is to load/save the user data at the beginning/end respectively of each interaction with the user (chat-bot). All the user data is wrapped in a predicate called user_data(). So all I have to do to get a complete dump of the current user data is to execute a listing(user_data/1) statement.

Is there a way to output the result of a listing() command from code running in a PEngines thread directly to a disk file that is in SWI-Prolog Quick Load Format? If so, is there a document that tells me how to do this?

Note: if there are restrictions in the Pengines sandbox that will prevent me from doing this, then please let me if there is a workaround. If there is none, then do you think if I mark the predicate that saves the listing data to the disk as a safe primitive that it is a reasonable security risk to do so? Let me know too if I won’t be able to load a Quick Load File due to the sandbox.

http://www.swi-prolog.org/pldoc/doc_for?object=sandbox%3Asafe_primitive/1

listing/1 is hooked in such a way that it displays the result in the browser. There is currently no way to dump a single predicate as .QLF. And, as you might have guessed, the sandbox doesn’t allow to write any files. So, you need to write a primitive that does precisely what you want, make sure it is safe in the sense that it doesn’t allow you to dump info the user shouldn’t be able to access and doesn’t write it in a location the user is not supposed to write to. Then declare this a safe primitive.

I’d have a look at library(persistency).

1 Like

Thanks Jan. This should not be too hard. The user has no route to the code that does the user data save/load operations on their behalf so they can not inject or retrieve data into or from that data store.

Also the save/load operation happens automatically with each user transaction and the result of the operation is never shown to the user. Everything happens behind the scenes and only to the local drive or to a hidden database server.

Is Prolog code running in the PEngines sandbox allowed to make HTTP requests? I’m asking for the eventual context where I use a database server to load/store the user data.