From c52ea5df2cbaad340765b2f8f27bd08d13fe149d Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Fri, 13 Sep 2024 13:14:19 +0530 Subject: [PATCH] update log level and naming convention --- .../emoji/DownloadableEmojiSpriteLoader.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/emoji/src/main/java/com/gluonhq/emoji/DownloadableEmojiSpriteLoader.java b/emoji/src/main/java/com/gluonhq/emoji/DownloadableEmojiSpriteLoader.java index 8cb245b..692af76 100644 --- a/emoji/src/main/java/com/gluonhq/emoji/DownloadableEmojiSpriteLoader.java +++ b/emoji/src/main/java/com/gluonhq/emoji/DownloadableEmojiSpriteLoader.java @@ -106,12 +106,12 @@ private void downloadSprites(int... sizes) { if (parentDir != null && !Files.exists(parentDir)) { Files.createDirectories(parentDir); } - Path tmpFilePath = getTmpFilePath(size); - LOG.fine("Creating tmp file: " + tmpFilePath); - Files.createFile(tmpFilePath); + Path lockFilePath = getLockFilePath(size); + LOG.fine(String.format("Creating lock file for size %s at %s", size, lockFilePath)); + Files.createFile(lockFilePath); LOG.fine("Download sprite file for size: " + size); String url = String.format(EMOJI_PNG_URL, commit, size); - downloadFile(new URI(url).toURL(), localFilePath, tmpFilePath); + downloadFile(new URI(url).toURL(), localFilePath, lockFilePath); } catch (IOException | URISyntaxException e) { LOG.severe("Download sprite failed: " + e.getMessage()); throw new RuntimeException("Unable to load local image file", e); @@ -137,12 +137,12 @@ public InputStream loadCSV() { return DownloadableEmojiSpriteLoader.class.getResourceAsStream("emoji.csv"); } - private void downloadFile(URL url, Path filePath, Path tmpFile) throws IOException { + private void downloadFile(URL url, Path filePath, Path lockFile) throws IOException { try (InputStream inputStream = url.openStream()) { Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING); LOG.fine("Sprite downloaded successfully as: " + filePath); - LOG.fine("Removing tmp file: " + tmpFile); - Files.delete(tmpFile); + LOG.fine("Removing tmp file: " + lockFile); + Files.delete(lockFile); } catch (IOException e) { LOG.log(Level.SEVERE, "Downloading file failed", e); } @@ -150,13 +150,13 @@ private void downloadFile(URL url, Path filePath, Path tmpFile) throws IOExcepti private boolean localFileExists(int size) { Path localFilePath = getLocalFilePath(size); - Path tmpFilePath = getTmpFilePath(size); - if (Files.exists(tmpFilePath)) { - LOG.fine("Temporary download file found"); - LOG.fine("Delete file and re-try downloading"); + Path lockFilePath = getLockFilePath(size); + if (Files.exists(lockFilePath)) { + LOG.info("Lock file found for size: " + size); + LOG.info("Delete file and re-try downloading"); try { Files.deleteIfExists(localFilePath); - Files.delete(tmpFilePath); + Files.delete(lockFilePath); return false; } catch (IOException e) { throw new RuntimeException("Unable to delete file: " + localFilePath); @@ -170,7 +170,7 @@ private Path getLocalFilePath(int size) { return Paths.get(String.format(LOCAL_PATH, commit), fileName); } - private Path getTmpFilePath(int size) { + private Path getLockFilePath(int size) { return Paths.get(String.format(LOCAL_PATH, commit)).resolve(size + ".downloading"); } }