Skip to content

Commit f488c71

Browse files
authored
Merge pull request #138 from testmycode/symbolic-link-fix
Detect projects behind symbolic links
2 parents 1ca63d1 + d27cc9a commit f488c71

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/UpdateExercisesAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void bgTaskFailed(Throwable ex) {
7474
});
7575

7676
for (final Exercise exercise : exercisesToUpdate) {
77-
final File projectDir = projectMediator.getProjectDirForExercise(exercise);
77+
final File projectDir = projectMediator.getProjectDirForExercise(exercise).toFile();
7878
eventBus.post(new InvokedEvent(exercise));
7979

8080

tmc-plugin/src/fi/helsinki/cs/tmc/model/ProjectMediator.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import java.io.File;
99
import java.io.IOException;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
1012
import java.util.ArrayList;
1113
import java.util.Arrays;
1214
import java.util.Collection;
@@ -114,21 +116,21 @@ public File getCourseRootDir(String courseName) {
114116
* <p>
115117
* The exercise must have a course name set.
116118
*/
117-
public File getProjectDirForExercise(Exercise ex) {
118-
String path =
119-
getProjectRootDir() + File.separator +
120-
ex.getCourseName() + File.separator +
121-
ex.getName().replaceAll("/", "-");
122-
return new File(path);
119+
public Path getProjectDirForExercise(Exercise ex) {
120+
Path path = Paths.get(
121+
getProjectRootDir(),
122+
ex.getCourseName(),
123+
ex.getName().replaceAll("/", "-"));
124+
return tryGetRealPath(path);
123125
}
124126

125127
/**
126128
* Returns the exercise associated with the given project, or null if none.
127129
*/
128130
public Exercise tryGetExerciseForProject(TmcProjectInfo project, CourseDb courseDb) {
129-
File projectDir = FileUtil.toFile(project.getProjectDir());
131+
Path projectDir = FileUtil.toFile(project.getProjectDir()).toPath();
130132
for (Exercise ex : courseDb.getCurrentCourseExercises()) {
131-
if (getProjectDirForExercise(ex).equals(projectDir)) {
133+
if (getProjectDirForExercise(ex).equals(tryGetRealPath(projectDir))) {
132134
return ex;
133135
}
134136
}
@@ -164,7 +166,7 @@ public TmcProjectInfo tryGetProjectOwningFile(FileObject fo) {
164166
public TmcProjectInfo tryGetProjectForExercise(Exercise exercise) {
165167
projectManager.clearNonProjectCache(); // Just to be sure.
166168

167-
File path = getProjectDirForExercise(exercise);
169+
File path = getProjectDirForExercise(exercise).toFile();
168170
FileObject fo = FileUtil.toFileObject(path);
169171
if (fo != null) {
170172
try {
@@ -259,4 +261,12 @@ public void scanForExternalChanges(Collection<TmcProjectInfo> projects) {
259261
fs.refresh(true);
260262
}
261263
}
264+
265+
private Path tryGetRealPath(Path path) {
266+
try {
267+
return path.toRealPath();
268+
} catch (IOException ex) {
269+
return path;
270+
}
271+
}
262272
}

0 commit comments

Comments
 (0)