Skip to content
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
1 change: 1 addition & 0 deletions gap/directories.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DeclareGlobalFunction("PKGMAN_PackageDir");
DeclareGlobalFunction("PKGMAN_RealPath");
DeclareGlobalFunction("PKGMAN_SetCustomPackageDir");
DeclareGlobalFunction("PKGMAN_CreateDirRecursively");
DeclareGlobalFunction("PKGMAN_InsertPackageDirectory");
Expand Down
21 changes: 20 additions & 1 deletion gap/directories.gi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ function()
return dir;
end);

# Resolve symlinks in <path> where GAP supports it (4.15 or newer), else
# return <path> unchanged. GAP 4.17 and newer store root and package
# directories with symlinks resolved (gap-system/gap#5930), so paths must be
# compared in this form (e.g. /var is /private/var on macOS).
InstallGlobalFunction(PKGMAN_RealPath,
function(path)
local res;
if IsBound(GAP_realpath) then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line tries to limit this change to versions that have GAP_realpath. Maybe this doesn't work then as yi expect?

res := GAP_realpath(path);
if res <> fail then
return res;
fi;
fi;
Comment thread
mtorpey marked this conversation as resolved.
return path;
end);

InstallGlobalFunction(PKGMAN_SetCustomPackageDir,
function(dir)
# Set the variable
Expand Down Expand Up @@ -120,8 +136,11 @@ end);

InstallGlobalFunction(PKGMAN_RemoveDir,
function(dir)
local realdir, pkgdir;
realdir := PKGMAN_RealPath(dir);
pkgdir := PKGMAN_RealPath(PKGMAN_PackageDir());
# this 'if' statement is a paranoid check - it should always be true
if StartsWith(dir, PKGMAN_PackageDir()) and dir <> PKGMAN_PackageDir() then
if StartsWith(realdir, pkgdir) and realdir <> pkgdir then
RemoveDirectoryRecursively(dir);
Comment thread
mtorpey marked this conversation as resolved.
Info(InfoPackageManager, 2, "Removed directory ", dir);
PKGMAN_RefreshPackageInfo();
Expand Down
5 changes: 3 additions & 2 deletions gap/packageinfo.gi
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ InstallGlobalFunction(PKGMAN_UserPackageInfo,
function(name)
local user_pkg_dir, allinfo, userinfo;

user_pkg_dir := PKGMAN_PackageDir();
user_pkg_dir := PKGMAN_RealPath(PKGMAN_PackageDir());
allinfo := PackageInfo(name);
userinfo := Filtered(allinfo, i -> StartsWith(i.InstallationPath, user_pkg_dir));
userinfo := Filtered(allinfo,
i -> StartsWith(PKGMAN_RealPath(i.InstallationPath), user_pkg_dir));

# Package not found
if ValueOption("warnIfNone") = true and Length(userinfo) = 0 then
Expand Down
19 changes: 19 additions & 0 deletions tst/symlink.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# If the user package directory is given through a symlink, it must still
# match the resolved path GAP 4.17 and newer store (gap-system/gap#5930).
gap> olddir := PKGMAN_CustomPackageDir;;
gap> tmp := DirectoryTemporary();;
gap> CreateDir(Filename(tmp, "real"));
true
gap> PKGMAN_Exec(Filename(tmp, ""), "ln", "-s", "real", "link");
rec( code := 0, output := "" )
gap> PKGMAN_Exec(Filename(tmp, ""), "cp", "-r",
> Filename(DirectoriesPackageLibrary("PackageManager", "tst/data/new"), "pmdummy"),
> "real/");
rec( code := 0, output := "" )
gap> PKGMAN_InsertPackageDirectory(Filename(tmp, "real"));;
gap> PKGMAN_CustomPackageDir := Filename(tmp, "link");;
gap> Length(PKGMAN_UserPackageInfo("pmdummy"));
1
gap> RemovePackage("pmdummy", false);
true
gap> PKGMAN_CustomPackageDir := olddir;;
3 changes: 3 additions & 0 deletions tst/testall.g
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ fi;
if not CompareVersionNumbers(version, ">=4.14") then
Add(PKGMAN_ExcludeTestFiles, "RecentGapOnly.tst");
fi;
if not CompareVersionNumbers(version, ">=4.15") then
Add(PKGMAN_ExcludeTestFiles, "symlink.tst"); # needs GAP_realpath
fi;

# Run tests
TestDirectory(DirectoriesPackageLibrary("PackageManager", "tst"),
Expand Down
Loading