Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andreachiera committed Aug 24, 2023
1 parent 7a79fc4 commit f5d8780
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/main/java/hudson/plugins/jobConfigHistory/FileHistoryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public SortedMap<String, HistoryDescr> getRevisions(final XmlFile xmlFile) {
private SortedMap<String, HistoryDescr> getRevisions(
final File configFile) {
final File historiesDir = getHistoryDir(configFile);
return getRevisions(historiesDir, configFile);
return getRevisionsFromHistoriesDir(historiesDir);
}

/**
Expand All @@ -547,8 +547,8 @@ private SortedMap<String, HistoryDescr> getRevisions(
* @param configFile for exception
* @return sorted map
*/
private SortedMap<String, HistoryDescr> getRevisions(
final File historiesDir, final File configFile) {
private SortedMap<String, HistoryDescr> getRevisionsFromHistoriesDir(
final File historiesDir) {
final File[] historyDirsOfItem = historiesDir
.listFiles(HistoryFileFilter.INSTANCE);
final TreeMap<String, HistoryDescr> map = new TreeMap<>();
Expand Down Expand Up @@ -1055,13 +1055,21 @@ private File[] returnEmptyFileArrayForNull(final File[] array) {

@Override
public SortedMap<String, HistoryDescr> getJobHistory(final String jobName) {
return getRevisions(new File(getJobHistoryRootDir(), jobName),
new File(jobName));
File jobHistoryRootDir = getJobHistoryRootDir();
File jobNameSubFolder = new File(jobHistoryRootDir, jobName);
if(!fileIsContainedInDirectory(jobNameSubFolder, jobHistoryRootDir)) {
return new TreeMap<>();
}
return getRevisionsFromHistoriesDir(jobNameSubFolder);
}

@Override
public SortedMap<String, HistoryDescr> getSystemHistory(final String name) {
return getRevisions(new File(historyRootDir, name), new File(name));
File systemSubFolder = new File(historyRootDir, name);
if(!fileIsContainedInDirectory(systemSubFolder, historyRootDir)) {
return new TreeMap<>();
}
return getRevisionsFromHistoriesDir(systemSubFolder);
}

@Deprecated
Expand Down Expand Up @@ -1335,6 +1343,13 @@ public XmlFile getOldRevision(final Node node, final String identifier) {
return new XmlFile(getConfigFile(historyDir));
}

private boolean fileIsContainedInDirectory(File file, File directory) {
try {
return file.toPath().toRealPath().startsWith(directory.toPath().toRealPath());
} catch (IOException ignored) {}
return false;
}

@Override
public boolean hasOldRevision(final Node node, final String identifier) {
final XmlFile oldRevision = getOldRevision(node, identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
removeEntryFromTable('table-row-' + JsConfigNr, JsConfigDate, JsJobName, JsMessage)
}
</script>
<button type="button" class="jenkins-button jenkins-button--destructive" onClick="removeEntryFromTable2('${configNr}', '${config.date}', '${message}')" value="X">
<button type="button" class="jenkins-button jenkins-button--destructive" data-config-date="${config.date}" onClick="removeEntryFromTable2('${configNr}', this.getAttribute('data-config-date'), '${message}')" value="X">
<l:icon src="symbol-trash-outline plugin-ionicons-api" class="icon-md" alt="${%Delete Revision}" />
</button>
</div>
Expand Down

0 comments on commit f5d8780

Please sign in to comment.