mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add ability to avoid backing up the tool before applying to patch. This makes Toolbox App apply patches ~30% faster
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.intellij.updater.Bootstrap
|
||||
Patcher-Version: 2.1
|
||||
Patcher-Version: 3.0
|
||||
|
||||
@@ -311,7 +311,9 @@ public class Patch {
|
||||
if (each.shouldApply(toDir, options)) actionsToProcess.add(each);
|
||||
}
|
||||
|
||||
forEach(actionsToProcess, "Backing up files...", ui, true, action -> action.backup(toDir, backupDir));
|
||||
if (backupDir != null) {
|
||||
forEach(actionsToProcess, "Backing up files...", ui, true, action -> action.backup(toDir, backupDir));
|
||||
}
|
||||
|
||||
List<PatchAction> appliedActions = new ArrayList<>();
|
||||
boolean shouldRevert = false;
|
||||
@@ -342,7 +344,9 @@ public class Patch {
|
||||
}
|
||||
|
||||
if (shouldRevert) {
|
||||
revert(appliedActions, backupDir, rootDir, ui);
|
||||
if (backupDir != null) {
|
||||
revert(appliedActions, backupDir, rootDir, ui);
|
||||
}
|
||||
appliedActions.clear();
|
||||
|
||||
if (cancelled) throw new OperationCancelledException();
|
||||
|
||||
@@ -27,6 +27,11 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class PatchFileCreator {
|
||||
private static final String PATCH_INFO_FILE_NAME = ".patch-info";
|
||||
/**
|
||||
* This property allows applying patches without creating backups. In this case a callee is responsible for that.
|
||||
* Example: JetBrains Toolbox App copies a tool it wants to update and then applies the patch.
|
||||
*/
|
||||
private static final String NO_BACKUP_PROPERTY = "no.backup";
|
||||
|
||||
public static Patch create(PatchSpec spec, File patchFile, UpdaterUI ui) throws IOException, OperationCancelledException {
|
||||
Patch patchInfo = new Patch(spec, ui);
|
||||
@@ -72,7 +77,12 @@ public class PatchFileCreator {
|
||||
public static boolean apply(PreparationResult preparationResult,
|
||||
Map<String, ValidationResult.Option> options,
|
||||
UpdaterUI ui) throws IOException, OperationCancelledException {
|
||||
return apply(preparationResult, options, Utils.createTempDir(), ui).applied;
|
||||
File backupDir = shouldSkipBackups() ? null : Utils.createTempDir();
|
||||
return apply(preparationResult, options, backupDir, ui).applied;
|
||||
}
|
||||
|
||||
private static boolean shouldSkipBackups() {
|
||||
return Boolean.parseBoolean(System.getProperty(NO_BACKUP_PROPERTY, "false"));
|
||||
}
|
||||
|
||||
public static Patch.ApplicationResult apply(PreparationResult preparationResult,
|
||||
|
||||
@@ -51,7 +51,8 @@ public class UpdateAction extends BaseUpdateAction {
|
||||
protected void doApply(ZipFile patchFile, File backupDir, File toFile) throws IOException {
|
||||
Runner.logger().info("Update action. File: " + toFile.getAbsolutePath());
|
||||
|
||||
File source = getSource(backupDir);
|
||||
//in case no backup is required
|
||||
File source = backupDir == null ? toFile : getSource(backupDir);
|
||||
if (!isMove()) {
|
||||
try (InputStream in = Utils.findEntryInputStream(patchFile, getPath())) {
|
||||
if (in == null) {
|
||||
|
||||
@@ -135,9 +135,11 @@ public class UpdateZipAction extends BaseUpdateAction {
|
||||
@Override
|
||||
protected void doApply(final ZipFile patchFile, File backupDir, File toFile) throws IOException {
|
||||
File temp = Utils.getTempFile(toFile.getName());
|
||||
//in case no backup is required
|
||||
File source = backupDir == null ? toFile : getSource(backupDir);
|
||||
|
||||
try (ZipOutputWrapper out = new ZipOutputWrapper(new FileOutputStream(temp), 0)) {
|
||||
processZipFile(getSource(backupDir), (entry, in) -> {
|
||||
processZipFile(source, (entry, in) -> {
|
||||
String path = entry.getName();
|
||||
if (myFilesToUpdate.contains(path)) {
|
||||
try (OutputStream entryOut = out.zipStream(path)) {
|
||||
|
||||
Reference in New Issue
Block a user