# HG changeset patch # User Markus Mützel # Date 1616346614 -3600 # Sun Mar 21 18:10:14 2021 +0100 # Node ID 7fb21e29630878b5ee0cfb83c5fb7a5b5ae051e9 # Parent ebc3f80673f00b3074aef3c0c9957ec6bed61597 pkg.m: Install local packages in version dependent path (bug #58299). * scripts/pkg/pkg.m: Store local package list in (platform-specific) version dependent path. * scripts/pkg/private/default_prefix.m: Change the default local package installation location to a (platform-specific) version dependent path. * scripts/pkg/private/install.m: Create directory for local package list if it doesn't exist yet. * libinterp/corefcn/defaults.cc (Fuser_config_dir, Fuser_data_dir): Add new functions to query platform-specific path for user data and user configuration files. * doc/interpreter/system.txi: Add docstring of new functions to manual. diff -r ebc3f80673f0 -r 7fb21e296308 doc/interpreter/system.txi --- a/doc/interpreter/system.txi Sun Mar 21 10:53:11 2021 +0100 +++ b/doc/interpreter/system.txi Sun Mar 21 18:10:14 2021 +0100 @@ -556,6 +556,10 @@ @DOCSTRING(verLessThan) +@DOCSTRING(user_config_dir) + +@DOCSTRING(user_data_dir) + @DOCSTRING(license) @DOCSTRING(memory) diff -r ebc3f80673f0 -r 7fb21e296308 libinterp/corefcn/defaults.cc --- a/libinterp/corefcn/defaults.cc Sun Mar 21 10:53:11 2021 +0100 +++ b/libinterp/corefcn/defaults.cc Sun Mar 21 18:10:14 2021 +0100 @@ -507,3 +507,40 @@ %!assert (ischar (OCTAVE_VERSION ())) %!error OCTAVE_VERSION (1) */ + +DEFUN (user_config_dir, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {cfg_dir = } user_config_dir () +Return the (platform-specific) directory for user configuration. +@seealso{user_data_dir} +@end deftypefn */) +{ + if (args.length () != 0) + print_usage (); + + return ovl (octave::sys::env::get_user_config_directory ()); +} + +/* +%!assert (ischar (user_config_dir ())) +%!error user_config_dir (1) +*/ + +DEFUN (user_data_dir, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {data_dir = } user_data_dir () +Return the (platform-specific) directory for user data. +@seealso{user_config_dir} +@end deftypefn */) +{ + if (args.length () != 0) + print_usage (); + + return ovl (octave::sys::env::get_user_data_directory ()); +} + +/* +%!assert (ischar (user_data_dir ())) +%!error user_data_dir (1) +*/ + diff -r ebc3f80673f0 -r 7fb21e296308 scripts/pkg/pkg.m --- a/scripts/pkg/pkg.m Sun Mar 21 10:53:11 2021 +0100 +++ b/scripts/pkg/pkg.m Sun Mar 21 18:10:14 2021 +0100 @@ -384,8 +384,10 @@ persistent user_prefix = false; persistent prefix = false; persistent archprefix = -1; - persistent local_list = tilde_expand (fullfile ("~", ".octave_packages")); - persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", + persistent local_list = fullfile (user_config_dir (), "octave", ... + __octave_config_info__ ("api_version"), ... + ".octave_packages"); + persistent global_list = fullfile (OCTAVE_HOME (), "share", "octave", ... "octave_packages"); ## If user is superuser (posix) or the process has elevated rights (Windows), diff -r ebc3f80673f0 -r 7fb21e296308 scripts/pkg/private/default_prefix.m --- a/scripts/pkg/private/default_prefix.m Sun Mar 21 10:53:11 2021 +0100 +++ b/scripts/pkg/private/default_prefix.m Sun Mar 21 18:10:14 2021 +0100 @@ -41,7 +41,8 @@ "packages"); endif else - prefix = tilde_expand (fullfile ("~", "octave")); + prefix = fullfile (user_data_dir (), "octave", ... + __octave_config_info__ ("api_version"), "packages"); archprefix = prefix; endif diff -r ebc3f80673f0 -r 7fb21e296308 scripts/pkg/private/install.m --- a/scripts/pkg/private/install.m Sun Mar 21 10:53:11 2021 +0100 +++ b/scripts/pkg/private/install.m Sun Mar 21 18:10:14 2021 +0100 @@ -282,6 +282,11 @@ if (ispc) local_packages = standardize_paths (local_packages); endif + if (! exist (fileparts (local_list), "dir") + && ! mkdir (fileparts (local_list))) + error ("Octave:pkg:install:local-dir", ... + "pkg: Could not create directory for local package configuration"); + endif save (local_list, "local_packages"); installed_pkgs_lst = {local_packages{:}, global_packages{:}}; endif