Skip to content

Commit 6a64e85

Browse files
committed
Fix a realpath failure when resolving course symlinks.
If one of the course links that are now maintained by webwork points to a location inside a non existent directory, then the `realpath` calls in `lib/WeBWorK/Utils/CourseDirectoryIntegrityCheck.pm` throw exceptions. This occurs both when checking for course upgrades and when upgrading courses. So those calls are wrapped in evals to prevent the exceptions. I have identified this as the cause of the issue discussed in https://forums.openwebwork.org/mod/forum/discuss.php?d=8757#p22321. To test this delete the Contrib link in a course's templates directory, and create a bad link with something like ```bash sudo ln -s /bad/location /opt/webwork/courses/courseId/templates/Contrib ``` Then go to the "Upgrade Courses" page in the admin course. It will give an error with the current develop or main branches. With this pull request it will show that the link structure of the course needs repair. Furthermore, repairing the link will work.
1 parent 75974fd commit 6a64e85

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/WeBWorK/Utils/CourseDirectoryIntegrityCheck.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ sub checkCourseLinks {
7474
# All links should actually be links, and should have the correct target. Note that the link target may also be
7575
# a link, and so the realpath of the configured link target and realpath of the course link path must be
7676
# compared to check that the link target is correct.
77-
my $good = -l $path && path($path)->realpath eq path($target)->realpath;
77+
my $good = -l $path && (eval { path($path)->realpath } // '') eq path($target)->realpath;
7878

7979
$links_ok = 0 if !$good;
8080
push @results, [ $link, $target, $path, $good ];
@@ -213,7 +213,7 @@ sub updateCourseLinks {
213213
my $targetIsCorrect = 0;
214214

215215
if (-l $path) {
216-
$targetIsCorrect = path($path)->realpath eq path($target)->realpath;
216+
$targetIsCorrect = (eval { path($path)->realpath } // '') eq path($target)->realpath;
217217
next if $targetIsCorrect;
218218
}
219219

0 commit comments

Comments
 (0)