[FIX] Исправлена работа HashedDir.walk

This commit is contained in:
Gravit 2019-05-21 01:14:56 +07:00
parent 1b80f4f7aa
commit 3af66f6280
3 changed files with 25 additions and 13 deletions

View file

@ -40,7 +40,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = null; AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = null;
ArrayList<String> removed = new ArrayList<>(); ArrayList<String> removed = new ArrayList<>();
diff.mismatch.walk(File.separator, (path, name, entry) -> { diff.mismatch.walk(File.separator, (path, name, entry) -> {
if(entry.getType() == HashedEntry.Type.DIR) return false; if(entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE;
HashedFile file = (HashedFile) entry; HashedFile file = (HashedFile) entry;
//Первый экспериментальный способ - честно обходим все возможные Store //Первый экспериментальный способ - честно обходим все возможные Store
Path ret = null; Path ret = null;
@ -82,7 +82,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
removed.add(path.concat(File.separator).concat(name)); removed.add(path.concat(File.separator).concat(name));
} }
} }
return false; return HashedDir.WalkAction.CONTINUE;
}); });
for(String rem : removed) for(String rem : removed)
{ {
@ -94,7 +94,7 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th
{ {
AtomicReference<Path> ret = null; AtomicReference<Path> ret = null;
en.hdir.walk(File.separator, (path, name, entry) -> { en.hdir.walk(File.separator, (path, name, entry) -> {
if(entry.getType() == HashedEntry.Type.DIR) return false; if(entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE;
HashedFile tfile = (HashedFile) entry; HashedFile tfile = (HashedFile) entry;
if(tfile.isSame(file)) if(tfile.isSame(file))
{ {
@ -105,14 +105,14 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th
{ {
LogHelper.debug("[DIR:%s] Confirmed file %s in %s", en.name, name, path); LogHelper.debug("[DIR:%s] Confirmed file %s in %s", en.name, name, path);
ret.set(tdir); ret.set(tdir);
return true; return HashedDir.WalkAction.STOP;
} }
} catch (IOException e) } catch (IOException e)
{ {
LogHelper.error("Check file error %s", e.getMessage()); LogHelper.error("Check file error %s", e.getMessage());
} }
} }
return false; return HashedDir.WalkAction.CONTINUE;
}); });
return ret.get(); return ret.get();
} }

View file

@ -204,7 +204,7 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro
LogHelper.error(ex); LogHelper.error(ex);
} }
} }
return false; return HashedDir.WalkAction.CONTINUE;
}); });
totalSize = diff.mismatch.size(); totalSize = diff.mismatch.size();
startTime = Instant.now(); startTime = Instant.now();

View file

@ -342,28 +342,40 @@ public void walk(CharSequence separator, WalkCallback callback) throws IOExcepti
String append = ""; String append = "";
walk(append, separator, callback, true); walk(append, separator, callback, true);
} }
public enum WalkAction
{
STOP, CONTINUE
}
@FunctionalInterface @FunctionalInterface
public interface WalkCallback { public interface WalkCallback {
boolean walked(String path, String name, HashedEntry entry) throws IOException; WalkAction walked(String path, String name, HashedEntry entry) throws IOException;
} }
private boolean walk(String append, CharSequence separator, WalkCallback callback, boolean noSeparator) throws IOException { private WalkAction walk(String append, CharSequence separator, WalkCallback callback, boolean noSeparator) throws IOException {
for (Map.Entry<String, HashedEntry> entry : map.entrySet()) { for (Map.Entry<String, HashedEntry> entry : map.entrySet()) {
HashedEntry e = entry.getValue(); HashedEntry e = entry.getValue();
if (e.getType() == Type.FILE) { if (e.getType() == Type.FILE) {
if (noSeparator) if (noSeparator)
if(callback.walked(append + entry.getKey(), entry.getKey(), e)) return true; {
WalkAction a = callback.walked(append + entry.getKey(), entry.getKey(), e);
if(a == WalkAction.STOP) return a;
}
else else
if(callback.walked(append + separator + entry.getKey(), entry.getKey(), e)) return true; {
WalkAction a = callback.walked(append + separator + entry.getKey(), entry.getKey(), e);
if(a == WalkAction.STOP) return a;
}
} else { } else {
String newAppend; String newAppend;
if (noSeparator) newAppend = append + entry.getKey(); if (noSeparator) newAppend = append + entry.getKey();
else newAppend = append + separator + entry.getKey(); else newAppend = append + separator + entry.getKey();
if(callback.walked(newAppend, entry.getKey(), e)) return true; WalkAction a = callback.walked(newAppend, entry.getKey(), e);
if(((HashedDir) e).walk(newAppend, separator, callback, false)) return true; if(a == WalkAction.STOP) return a;
a = ((HashedDir) e).walk(newAppend, separator, callback, false);
if(a == WalkAction.STOP) return a;
} }
} }
return false; return WalkAction.CONTINUE;
} }
} }