Open marcjoancr opened 2 months ago
I just checked the code (sorry for not doing it before opening the issue):
public long getUsedSpace() {
return FileUtils.sizeOfDirectory(SERVER_FOLDER);
}
Seems like if you do a try/catch you will not return any value, I suggest doing a crawler in order to check the files safely and always having a value to return, like so:
public long getUsedSpace() {
final long[] size = {0};
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
size[0] += attrs.size();
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
if (exc instanceof NoSuchFileException) {
return FileVisitResult.CONTINUE;
}
}
});
return size[0];
}
Disclaimer: Haven't tested it.
I have
CoreProtect
and it looks like uses db-wal, and it is a volatile file. If you use FileUtils crawling the files maybe check if it exists before checking size may solve the bug or maybe just with a simple try/catch of NoSuchFileException.