LogtalkDotOrg / logtalk3

Logtalk - declarative object-oriented logic programming language
https://logtalk.org
Apache License 2.0
415 stars 30 forks source link

`scratch` folder may result in 'Initialization goal failed' in swi-prolog pack #62

Closed Vimos closed 6 years ago

Vimos commented 6 years ago

I installed logtalk pack in swi-prolog with root user.

?- pack_info(logtalk).
Package:                logtalk
Title:                  Logtalk - Object-Oriented Logic Programming Language
Installed version:      3.16.0
Installed in directory: /usr/lib/swi-prolog/pack/logtalk
Author:                 Paulo Moura <pmoura@logtalk.org>
Maintainer:             Paulo Moura <pmoura@logtalk.org>
Packager:               Paulo Moura <pmoura@logtalk.org>
Home page:              https://logtalk.org/
Download URL:           https://logtalk.org/files/swi-prolog/packs/logtalk-3.16.0.tgz
Provided libraries:     logtalk
true.

When I start to run use_module(library(logtalk)). in swipl using common user, a warning is produced

?- use_module(library(logtalk)).
Warning: /usr/lib/swi-prolog/pack/logtalk/logtalk-3.16.0/integration/logtalk_swi.pl:24:
    /usr/lib/swi-prolog/pack/logtalk/logtalk-3.16.0/core/core.pl:23326: Initialization goal failed
true.

I find that this is caused by the scratch folder, when I chown the folder to the common user, the warning is gone.

➜  logtalk sudo chown -R vimos:vimos /usr/lib/swi-prolog/pack/logtalk/logtalk-3.16.0/scratch
➜  logtalk swipl                                                                            
Welcome to SWI-Prolog (threaded, 64 bits, version 7.6.4)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- use_module(library(logtalk)).
true.

?- ^D
% halt

Maybe this scratch_directory needs to be user specific to avoid such warning.

pmoura commented 6 years ago

The pack sets both the LOGTALKHOME and LOGTALKUSER environment variables to the location of the pack and indeed expects the $LOGTALKUSER/scratch directory to be user-writable. Any reason to install the pack as root but run it as a non-admin user? Note that the pack is handy for some deployment scenarios but not advised for development. You can override the scratch directory by adding to your .swiplrc the following code:

:- multifile(logtalk_library_path/2).
:- dynamic(logtalk_library_path/2).

logtalk_library_path(scratch_directory, '$HOME/scratch').

Adjust the path to the desired location.

Vimos commented 6 years ago

That makes good sense, thank you for the explanation!