From 4ec2f2461a3f624e39b388d6979a2a8c4a07263d Mon Sep 17 00:00:00 2001 From: "Vladimir.Orlov" Date: Tue, 6 Dec 2016 11:25:44 +0300 Subject: [PATCH] Updater: patches for symbolic link fixed. Added more information in updater log file. --- .../com/intellij/updater/CreateAction.java | 1 + .../com/intellij/updater/DeleteAction.java | 2 ++ .../com/intellij/updater/DiffCalculator.java | 5 +++-- .../com/intellij/updater/UpdateAction.java | 1 + updater/src/com/intellij/updater/Utils.java | 20 ++++++++++--------- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/updater/src/com/intellij/updater/CreateAction.java b/updater/src/com/intellij/updater/CreateAction.java index 8b3b5e527eaa..f26f95ca0c5b 100644 --- a/updater/src/com/intellij/updater/CreateAction.java +++ b/updater/src/com/intellij/updater/CreateAction.java @@ -73,6 +73,7 @@ public class CreateAction extends PatchAction { @Override protected void doApply(ZipFile patchFile, File backupDir, File toFile) throws IOException { + Runner.logger().info("Create action. File: " + toFile.getAbsolutePath()); prepareToWriteFile(toFile); ZipEntry entry = Utils.getZipEntry(patchFile, myPath); diff --git a/updater/src/com/intellij/updater/DeleteAction.java b/updater/src/com/intellij/updater/DeleteAction.java index b7c742fdb01f..9aff0b12b5d4 100644 --- a/updater/src/com/intellij/updater/DeleteAction.java +++ b/updater/src/com/intellij/updater/DeleteAction.java @@ -59,9 +59,11 @@ public class DeleteAction extends PatchAction { @Override protected void doApply(ZipFile patchFile, File backupDir, File toFile) throws IOException { + Runner.logger().info("Delete action. File: " + toFile.getAbsolutePath()); //NOTE: a folder can be deleted only in case if it does not contain any user's files/folders. File[] listFiles = toFile.listFiles(); if (!toFile.isDirectory() || (listFiles != null && listFiles.length == 0)) { + Runner.logger().info("Delete: " + toFile.getAbsolutePath()); Utils.delete(toFile); } } diff --git a/updater/src/com/intellij/updater/DiffCalculator.java b/updater/src/com/intellij/updater/DiffCalculator.java index e5930ac382fb..49ebd57c661b 100644 --- a/updater/src/com/intellij/updater/DiffCalculator.java +++ b/updater/src/com/intellij/updater/DiffCalculator.java @@ -42,9 +42,10 @@ public class DiffCalculator { // Find first by content for (Map.Entry create : toCreate.entrySet()) { boolean isDir = create.getKey().endsWith("/"); + boolean isLink = create.getKey().endsWith(".dylib"); String source = byContent.get(create.getValue()); boolean found = false; - if (source != null && !isDir) { + if (source != null && !isDir && !isLink) { // Found a file with the same content use it, unless it's critical if (!critical.contains(source)) { result.filesToUpdate.put(create.getKey(), new Update(source, result.filesToDelete.get(source), true)); @@ -54,7 +55,7 @@ public class DiffCalculator { else { File fileToCreate = new File(create.getKey()); List sameName = byName.get(fileToCreate.getName()); - if (sameName != null && !isDir) { + if (sameName != null && !isDir && !isLink) { String best = findBestCandidateForMove(sameName, create.getKey()); // Found a file with the same name, if it's not critical use it, worst case as big as a create. if (!critical.contains(best)) { diff --git a/updater/src/com/intellij/updater/UpdateAction.java b/updater/src/com/intellij/updater/UpdateAction.java index ce91343bb3fd..70ea9e3a3ba4 100644 --- a/updater/src/com/intellij/updater/UpdateAction.java +++ b/updater/src/com/intellij/updater/UpdateAction.java @@ -50,6 +50,7 @@ public class UpdateAction extends BaseUpdateAction { @Override protected void doApply(ZipFile patchFile, File backupDir, File toFile) throws IOException { File source = getSource(backupDir); + Runner.logger().info("Update action. File: " + toFile.getAbsolutePath()); File updated; if (!myIsMove) { updated = Utils.createTempFile(); diff --git a/updater/src/com/intellij/updater/Utils.java b/updater/src/com/intellij/updater/Utils.java index 4273509a8dc1..c4553ffd8536 100644 --- a/updater/src/com/intellij/updater/Utils.java +++ b/updater/src/com/intellij/updater/Utils.java @@ -117,17 +117,19 @@ public class Utils { } public static void copy(File from, File to) throws IOException { - Runner.logger().info("from " + from.getPath() + " to " + to.getPath()); if (from.isDirectory()) { - to.mkdirs(); - File[] files = from.listFiles(); - if (files == null) throw new IOException("Cannot get directory's content: " + from); - for (File each : files) { - copy(each, new File(to, each.getName())); + if (! to.exists()) { + Runner.logger().info("Dir: " + from.getPath() + " to " + to.getPath()); + to.mkdirs(); + File[] files = from.listFiles(); + if (files == null) throw new IOException("Cannot get directory's content: " + from); + for (File each : files) { + copy(each, new File(to, each.getName())); + } } - } - else { - if (! isLink(from)) { + } else { + if (! isLink(from) && from.exists()) { + Runner.logger().info("File: " + from.getPath() + " to " + to.getPath()); InputStream in = new BufferedInputStream(new FileInputStream(from)); try { copyStreamToFile(in, to);