@VisibleForTesting Path getStorageFilePath() { TelemetryPathManager.migrate(TELEMETRY_PRODUCT_KEY, getOldStorageFilePath()); return TelemetryPathManager.getPath(TELEMETRY_PRODUCT_KEY); }
/** * If telemetry storage doesn't exist at the current location, * copy from the specified old path. * * @param productKey short name of the product, for example "idea", "eclipse" * @param oldPath old path of telemetry storage */ public static void migrate(String productKey, Path oldPath) { Path newPath = getPath(productKey); if (newPath.toFile().isFile() || !oldPath.toFile().exists()) { return; } try { if (!newPath.getParent().toFile().exists()) { Files.createDirectories(newPath.getParent()); } Files.copy(oldPath, newPath); } catch (IOException e) { if (SonarLintUtils.isInternalDebugEnabled()) { LOG.error("Failed to migrate telemetry storage", e); } } } }
static Path getStorageFilePath() { TelemetryPathManager.migrate(TELEMETRY_PRODUCT_KEY, getOldStorageFilePath()); return TelemetryPathManager.getPath(TELEMETRY_PRODUCT_KEY); }