Skip to content

Commit 5a37bf7

Browse files
committed
Fixes #2950 : don't partially canonicalize in GitRepository
1 parent 80a75b4 commit 5a37bf7

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ private HistoryRevResult getHistoryRev(
195195
* Be careful, git uses only forward slashes in its command and output (not in file path).
196196
* Using backslashes together with git show will get empty output and 0 status code.
197197
*/
198-
String filename = Paths.get(getDirectoryName()).relativize(Paths.get(fullpath))
199-
.toString()
200-
.replace(File.separatorChar, '/');
198+
String filename = Paths.get(getCanonicalDirectoryName()).relativize(
199+
Paths.get(fullpath)).toString().replace(File.separatorChar, '/');
201200
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
202201
String[] argv = {
203202
RepoCommand,
@@ -234,13 +233,9 @@ boolean getHistoryGet(
234233
String fullpath;
235234
try {
236235
fullpath = new File(parent, basename).getCanonicalPath();
237-
} catch (IOException exp) {
238-
LOGGER.log(Level.SEVERE, exp, new Supplier<String>() {
239-
@Override
240-
public String get() {
241-
return String.format("Failed to get canonical path: %s/%s", parent, basename);
242-
}
243-
});
236+
} catch (IOException e) {
237+
LOGGER.log(Level.WARNING, e, () -> String.format(
238+
"Failed to get canonical path: %s/%s", parent, basename));
244239
return false;
245240
}
246241

@@ -265,7 +260,14 @@ public String get() {
265260
}
266261

267262
if (origpath != null) {
268-
final String fullRenamedPath = Paths.get(getDirectoryName(), origpath).toString();
263+
String fullRenamedPath;
264+
try {
265+
fullRenamedPath = Paths.get(getCanonicalDirectoryName(), origpath).toString();
266+
} catch (IOException e) {
267+
LOGGER.log(Level.WARNING, e, () -> String.format(
268+
"Failed to get canonical path: .../%s", origpath));
269+
return false;
270+
}
269271
if (!fullRenamedPath.equals(fullpath)) {
270272
result = getHistoryRev(sink, fullRenamedPath, rev);
271273
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
2525

@@ -54,11 +54,9 @@ public class RepositoryInfo implements Serializable {
5454

5555
private static final long serialVersionUID = 3L;
5656

57-
// dummy to avoid storing absolute path in XML encoded configuration
58-
// Do not use this member.
59-
private transient String directoryName;
60-
6157
private String directoryNameRelative;
58+
private transient String directoryNameCanonical;
59+
6260
protected Boolean working;
6361
protected String type; // type of the repository, should be unique
6462
protected boolean remote;
@@ -127,6 +125,7 @@ public String getDirectoryNameRelative() {
127125
*/
128126
public void setDirectoryNameRelative(String dir) {
129127
this.directoryNameRelative = dir;
128+
this.directoryNameCanonical = null;
130129
}
131130

132131
/**
@@ -137,7 +136,18 @@ public void setDirectoryNameRelative(String dir) {
137136
public String getDirectoryName() {
138137
return Paths.get(RuntimeEnvironment.getInstance().getSourceRootPath(),
139138
directoryNameRelative).toString();
139+
}
140140

141+
/**
142+
* Get the name of the root directory for this repository.
143+
*
144+
* @return the name of the root directory
145+
*/
146+
public String getCanonicalDirectoryName() throws IOException {
147+
if (directoryNameCanonical == null) {
148+
directoryNameCanonical = new File(getDirectoryName()).getCanonicalPath();
149+
}
150+
return directoryNameCanonical;
141151
}
142152

143153
/**

0 commit comments

Comments
 (0)