| 268 | } |
| 269 | |
| 270 | public static void reportCrashFiles(CairoConfiguration cairoConfiguration, Log log) { |
| 271 | final CharSequence dbRoot = cairoConfiguration.getDbRoot(); |
| 272 | final FilesFacade ff = cairoConfiguration.getFilesFacade(); |
| 273 | final int maxFiles = cairoConfiguration.getMaxCrashFiles(); |
| 274 | DirectUtf8StringZ name = new DirectUtf8StringZ(); |
| 275 | try (Path path = new Path(); Path other = new Path()) { |
| 276 | path.of(dbRoot).slash(); |
| 277 | other.of(dbRoot).slash(); |
| 278 | |
| 279 | int plen = path.size(); |
| 280 | AtomicInteger counter = new AtomicInteger(0); |
| 281 | FilesFacadeImpl.INSTANCE.iterateDir(path.$(), (pUtf8NameZ, type) -> { |
| 282 | if (Files.notDots(pUtf8NameZ)) { |
| 283 | name.of(pUtf8NameZ); |
| 284 | if (Utf8s.startsWithAscii(name, cairoConfiguration.getOGCrashFilePrefix()) && type == Files.DT_FILE) { |
| 285 | path.trimTo(plen).concat(pUtf8NameZ).$(); |
| 286 | boolean shouldRename = false; |
| 287 | do { |
| 288 | other.trimTo(plen).concat(cairoConfiguration.getArchivedCrashFilePrefix()).put(counter.getAndIncrement()).put(".log").$(); |
| 289 | if (!ff.exists(other.$())) { |
| 290 | shouldRename = counter.get() <= maxFiles; |
| 291 | break; |
| 292 | } |
| 293 | } while (counter.get() < maxFiles); |
| 294 | if (shouldRename && ff.rename(path.$(), other.$()) == 0) { |
| 295 | log.critical().$("found crash file [path=").$(other).I$(); |
| 296 | } else { |
| 297 | log.critical().$("could not rename crash file [path=").$(path).$(", errno=").$(ff.errno()).$(", index=").$(counter.get()).$(", max=").$(maxFiles).I$(); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | }); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | public void extractSite() throws IOException { |
| 306 | final byte[] buffer = new byte[1024 * 1024]; |