mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Fixes for potential stack overflow
This commit is contained in:
parent
62cb424040
commit
bd06633931
2 changed files with 21 additions and 13 deletions
|
@ -788,13 +788,20 @@ public abstract class DataStorage {
|
|||
|
||||
public Set<DataStoreEntry> getDeepStoreChildren(DataStoreEntry entry) {
|
||||
var set = new HashSet<DataStoreEntry>();
|
||||
getStoreChildren(entry).forEach(c -> {
|
||||
set.add(c);
|
||||
set.addAll(getDeepStoreChildren(c));
|
||||
});
|
||||
getDeepStoreChildren(entry, set);
|
||||
return set;
|
||||
}
|
||||
|
||||
private void getDeepStoreChildren(DataStoreEntry entry, Set<DataStoreEntry> current) {
|
||||
getStoreChildren(entry).forEach(c -> {
|
||||
var added = current.add(c);
|
||||
// Guard against loop
|
||||
if (added) {
|
||||
getDeepStoreChildren(c, current);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Set<DataStoreEntry> getStoreChildren(DataStoreEntry entry) {
|
||||
if (entry.getValidity() == DataStoreEntry.Validity.LOAD_FAILED) {
|
||||
return Set.of();
|
||||
|
|
|
@ -87,17 +87,18 @@ public class SimpleScriptStore extends ScriptStore implements ShellInitCommand.T
|
|||
}
|
||||
|
||||
public void queryFlattenedScripts(LinkedHashSet<DataStoreEntryRef<SimpleScriptStore>> all) {
|
||||
// Prevent loop
|
||||
DataStoreEntryRef<SimpleScriptStore> ref = getSelfEntry().ref();
|
||||
all.add(ref);
|
||||
getEffectiveScripts().stream()
|
||||
.filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef))
|
||||
.forEach(scriptStoreDataStoreEntryRef -> {
|
||||
var added = all.add(ref);
|
||||
// Prevent loop
|
||||
if (added) {
|
||||
getEffectiveScripts().stream().filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef)).forEach(
|
||||
scriptStoreDataStoreEntryRef -> {
|
||||
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(all);
|
||||
});
|
||||
all.remove(ref);
|
||||
all.add(ref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataStoreEntryRef<ScriptStore>> getEffectiveScripts() {
|
||||
|
|
Loading…
Reference in a new issue