fix: check if folder exists before trying to create it

This commit is contained in:
zaaarf 2024-09-28 15:56:04 +02:00
parent db89c781a6
commit 7995b8db45
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
2 changed files with 6 additions and 2 deletions

View file

@ -47,8 +47,11 @@ public class FileUtil {
if(found == null) { if(found == null) {
VirtualFile lastParent = contentRoot; VirtualFile lastParent = contentRoot;
String[] path = bufferName.split("/"); String[] path = bufferName.split("/");
for(int i = 0; i < path.length - 1; i++) for(int i = 0; i < path.length - 1; i++) {
lastParent = lastParent.createChildDirectory(requestor, path[i]); VirtualFile current = lastParent.findChild(path[i]);
if(current == null) current = lastParent.createChildDirectory(requestor, path[i]);
lastParent = current;
}
found = lastParent.createChildData(requestor, path[path.length - 1]); found = lastParent.createChildData(requestor, path[path.length - 1]);
} }

View file

@ -53,6 +53,7 @@ public class BufferCallback implements Consumer<BufferController> {
() -> changeList.forEach((change) -> { () -> changeList.forEach((change) -> {
editor.getDocument().replaceString((int) change.start, (int) change.end, change.content); editor.getDocument().replaceString((int) change.start, (int) change.end, change.content);
// check for validity, force-sync if mismatch // check for validity, force-sync if mismatch
// TODO: prompt instead of doing it silently
if(change.hash.isPresent() && change.hash.getAsLong() != Extensions.hash(editor.getDocument().getText())) { if(change.hash.isPresent() && change.hash.getAsLong() != Extensions.hash(editor.getDocument().getText())) {
try { try {
editor.getDocument().setText(bufferController.getContent()); editor.getDocument().setText(bufferController.getContent());