From 88d71b34e9f5143efb1a9ee45edfeb5d60ecca31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 6 Feb 2025 01:17:58 +0100 Subject: [PATCH 1/3] Make all root paths absolute --- lib/package.gi | 1 + src/sysroots.c | 17 ++++++++++++++++- src/sysroots.h | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/package.gi b/lib/package.gi index ba0612a535..94a9ecdbca 100644 --- a/lib/package.gi +++ b/lib/package.gi @@ -1864,6 +1864,7 @@ InstallGlobalFunction( SetPackagePath, function( pkgname, pkgpath ) InstallGlobalFunction( ExtendRootDirectories, function( rootpaths ) local i; + rootpaths:= List( rootpaths, GAP_realpath ); rootpaths:= Filtered( rootpaths, path -> not path in GAPInfo.RootPaths ); if not IsEmpty( rootpaths ) then # 'DirectoriesLibrary' concatenates root paths with directory names. diff --git a/src/sysroots.c b/src/sysroots.c index 42e4e42fe9..29784f5310 100644 --- a/src/sysroots.c +++ b/src/sysroots.c @@ -18,6 +18,7 @@ #include "sysstr.h" #include "system.h" +#include #include @@ -197,7 +198,7 @@ void SySetGapRootPath(const Char * string) return; const UInt userhomelen = strlen(userhome); for (i = 0; i < MAX_GAP_DIRS && SyGapRootPaths[i][0]; i++) { - const UInt pathlen = strlen(SyGapRootPaths[i]); + UInt pathlen = strlen(SyGapRootPaths[i]); if (SyGapRootPaths[i][0] == '~' && userhomelen + pathlen < sizeof(SyGapRootPaths[i])) { SyMemmove(SyGapRootPaths[i] + userhomelen, @@ -205,6 +206,20 @@ void SySetGapRootPath(const Char * string) SyGapRootPaths[i] + 1, pathlen); memcpy(SyGapRootPaths[i], userhome, userhomelen); } + + // convert all paths to absolute paths + Char tempstr[GAP_PATH_MAX]; + + if (NULL == realpath(SyGapRootPaths[i], tempstr)) { + SySetErrorNo(); + } else { + strxcpy(SyGapRootPaths[i], tempstr, sizeof(SyGapRootPaths[i])); + pathlen = strlen(SyGapRootPaths[i]); + if (SyGapRootPaths[i][pathlen - 1] != '/') { + SyGapRootPaths[i][pathlen] = '/'; + SyGapRootPaths[i][pathlen + 1] = '\0'; + } + } } } diff --git a/src/sysroots.h b/src/sysroots.h index ae7341ce94..264e89cb43 100644 --- a/src/sysroots.h +++ b/src/sysroots.h @@ -38,7 +38,7 @@ void SySetGapRootPath(const Char * string); ** ** must point to a buffer of at least characters. This function ** then searches for a readable file with the name in the system -** area. If sich a file is found then its absolute path is copied into +** area. If such a file is found then its absolute path is copied into ** , and is returned. If no file is found or if is not big ** enough, then is set to an empty string and NULL is returned. */ From ff9537eb7148ed0aea9a1240f1d9e667045bfd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 6 Feb 2025 01:18:10 +0100 Subject: [PATCH 2/3] Make all package dirs absolute --- lib/package.gi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/package.gi b/lib/package.gi index 94a9ecdbca..af34bf2596 100644 --- a/lib/package.gi +++ b/lib/package.gi @@ -304,7 +304,7 @@ InstallGlobalFunction( InitializePackagesInfoRecords, function( arg ) # the first time this is called, add the cmd line args to the list if IsEmpty(GAPInfo.PackageDirectories) then for pkgdirstrs in GAPInfo.CommandLineOptions.packagedirs do - pkgdirs:= List( SplitString( pkgdirstrs, ";" ), Directory ); + pkgdirs:= List( List( SplitString( pkgdirstrs, ";" ), GAP_realpath ), Directory ); for pkgdir in pkgdirs do if not pkgdir in GAPInfo.PackageDirectories then Add( GAPInfo.PackageDirectories, pkgdir ); @@ -1897,8 +1897,10 @@ InstallGlobalFunction( ExtendPackageDirectories, function( paths_or_dirs ) changed:= false; for p in paths_or_dirs do if IsString( p ) then - p:= Directory( p ); - elif not IsDirectory( p ) then + p:= Directory( GAP_realpath ( p ) ); + elif IsDirectory( p ) then + p:= Directory( GAP_realpath ( p![1] ) ); + else Error("input must be a list of path strings or directory objects"); fi; if not p in GAPInfo.PackageDirectories then From 7bbf142c7d358464825bdcfbd89d635063cda2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 14 Feb 2025 10:15:26 +0100 Subject: [PATCH 3/3] Update src/sysroots.c Co-authored-by: Max Horn --- src/sysroots.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sysroots.c b/src/sysroots.c index 29784f5310..acef6363ad 100644 --- a/src/sysroots.c +++ b/src/sysroots.c @@ -208,7 +208,7 @@ void SySetGapRootPath(const Char * string) } // convert all paths to absolute paths - Char tempstr[GAP_PATH_MAX]; + char tempstr[PATH_MAX]; if (NULL == realpath(SyGapRootPaths[i], tempstr)) { SySetErrorNo();