Skip to content

Make all root paths and package directories absolute paths #5930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
# 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 );
Expand Down Expand Up @@ -1864,6 +1864,7 @@
InstallGlobalFunction( ExtendRootDirectories, function( rootpaths )
local i;

rootpaths:= List( rootpaths, GAP_realpath );

Check warning on line 1867 in lib/package.gi

View check run for this annotation

Codecov / codecov/patch

lib/package.gi#L1867

Added line #L1867 was not covered by tests
rootpaths:= Filtered( rootpaths, path -> not path in GAPInfo.RootPaths );
if not IsEmpty( rootpaths ) then
# 'DirectoriesLibrary' concatenates root paths with directory names.
Expand Down Expand Up @@ -1896,8 +1897,10 @@
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 ) );

Check warning on line 1900 in lib/package.gi

View check run for this annotation

Codecov / codecov/patch

lib/package.gi#L1900

Added line #L1900 was not covered by tests
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
Expand Down
17 changes: 16 additions & 1 deletion src/sysroots.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sysstr.h"
#include "system.h"

#include <limits.h>
#include <stdlib.h>


Expand Down Expand Up @@ -197,14 +198,28 @@ 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,
// don't copy the ~ but the trailing '\0'
SyGapRootPaths[i] + 1, pathlen);
memcpy(SyGapRootPaths[i], userhome, userhomelen);
}

// convert all paths to absolute paths
char tempstr[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';
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sysroots.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void SySetGapRootPath(const Char * string);
**
** <buf> must point to a buffer of at least <size> characters. This function
** then searches for a readable file with the name <filename> 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
** <buf>, and <buf> is returned. If no file is found or if <buf> is not big
** enough, then <buf> is set to an empty string and NULL is returned.
*/
Expand Down
Loading