Browse Source

Pull request #2434: REPORT-40472 [回归]修复更新升级还原到以前版本后,还可以还原到以前版本

Merge in DESIGN/design from ~BRYANT/design:release/10.0 to release/10.0

* commit '27d5ffff59bad2531145c756177af14582a0abd3':
  REPORT-40472 [回归]修复更新升级还原到以前版本后,还可以还原到以前版本
  REPORT-40472 [回归]修复更新升级还原到以前版本后,还可以还原到以前版本
  REPORT-40472 备份文件夹内残存文件夹没有清理
  REPORT-40472 备份文件夹内残存文件夹没有清理
feature/big-screen
Bryant 4 years ago
parent
commit
5a1dbcdc84
  1. 129
      designer-base/src/main/java/com/fr/design/update/factory/DirectoryOperationFactory.java
  2. 4
      designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreDialog.java
  3. 4
      designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java
  4. 40
      designer-base/src/main/java/com/fr/design/update/utils/UpdateFileUtils.java
  5. 22
      designer-base/src/test/java/com/fr/design/update/utils/UpdateFileUtilsTest.java

129
designer-base/src/main/java/com/fr/design/update/factory/DirectoryOperationFactory.java

@ -1,129 +0,0 @@
package com.fr.design.update.factory;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
/**
* Created by XINZAI on 2018/8/21.
*/
public class DirectoryOperationFactory {
/**
* 新建一个目录
*
* @param dirPath 目录路径
*/
public static void createNewDirectory(String dirPath) {
try {
File newDirPath = new File(dirPath);
if (!newDirPath.exists()) {
StableUtils.mkdirs(newDirPath);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage());
}
}
/**
* 删除目录
*
* @param dirPath 目录路径
*/
public static void deleteDirectory(String dirPath) {
try {
File dir = new File(dirPath);
if (dir.isDirectory()) {
File[] file = dir.listFiles();
for (File fileTemp : file) {
deleteDirectory(fileTemp.toString());
fileTemp.delete();
}
} else {
dir.delete();
}
dir.delete();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage());
}
}
/**
* 复制目录
*
* @param oldDirPath 被复制目录
* @param newDirPath 新目录
*/
public static void copyDirectory(String oldDirPath, String newDirPath) {
File oldDir = new File(oldDirPath);
if (oldDir.isDirectory()) {
StableUtils.mkdirs(new File(newDirPath));
File[] files = oldDir.listFiles();
for (File fileTemp : files) {
copyDirectory(fileTemp.toString(), newDirPath + "/" + fileTemp.getName());
}
} else {
try {
copy(oldDirPath, newDirPath);
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage());
}
}
}
private static void copy(String path1, String path2) throws IOException {
try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(path1)));
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path2)))) {
byte[] date = new byte[in.available()];
in.read(date);
out.write(date);
}
}
/**
* 移动目录
*
* @param oldDirPath 被移动目录
* @param newDirPath 新目录
*/
public static void moveDirectory(String oldDirPath, String newDirPath) {
copyDirectory(oldDirPath, newDirPath);
deleteDirectory(oldDirPath);
}
/**
* 列出过滤后的文件
*
* @param installHome 安装目录
* @param backupdir 备份目录
* @return String数组
*/
public static String[] listFilteredFiles(String installHome, String backupdir) {
File backupDir = new File(StableUtils.pathJoin(installHome, backupdir));
StableUtils.mkdirs(backupDir);
File[] fileNames = backupDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
String[] jarFileName = new String[fileNames.length];
int j = 0;
for (File fileName : fileNames) {
if ((fileName.isDirectory()) && (ArrayUtils.getLength(fileName.listFiles()) > 0)) {//判断备份文件夹中是否为空,为空不显示
jarFileName[j++] = fileName.getName();
}
}
return Arrays.copyOf(jarFileName, j);
}
}

4
designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreDialog.java

@ -4,7 +4,7 @@ import com.fr.decision.update.data.UpdateConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.update.factory.DirectoryOperationFactory;
import com.fr.design.update.utils.UpdateFileUtils;
import com.fr.design.update.ui.widget.ColorfulCellRender;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.ArrayUtils;
@ -86,7 +86,7 @@ public class RestoreDialog extends JDialog {
JPanel jarListPane = new JPanel();
jarListPane.setLayout(new BoxLayout(jarListPane, BoxLayout.Y_AXIS));
String[] jarBackupFiles = DirectoryOperationFactory.listFilteredFiles(StableUtils.getInstallHome(), UpdateConstants.DESIGNER_BACKUP_DIR);
String[] jarBackupFiles = UpdateFileUtils.listFilteredFiles(StableUtils.getInstallHome(), UpdateConstants.DESIGNER_BACKUP_DIR);
ArrayUtils.reverse(jarBackupFiles);
String[] jarFilesList = ((jarBackupFiles.length < NUMOFCELL_LEAST) ? Arrays.copyOf(jarBackupFiles, NUMOFCELL_LEAST) : jarBackupFiles);

4
designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java

@ -17,7 +17,7 @@ import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.update.actions.FileProcess;
import com.fr.design.update.domain.UpdateInfoCachePropertyManager;
import com.fr.design.update.factory.DirectoryOperationFactory;
import com.fr.design.update.utils.UpdateFileUtils;
import com.fr.design.update.ui.widget.LoadingLabel;
import com.fr.design.update.ui.widget.UpdateActionLabel;
import com.fr.design.update.ui.widget.UpdateInfoTable;
@ -320,7 +320,7 @@ public class UpdateMainDialog extends UIDialog {
}
});
//choose RestoreLabel to show
boolean isNeedRestore = ArrayUtils.isNotEmpty(DirectoryOperationFactory.listFilteredFiles(StableUtils.getInstallHome(), getBackupDirectory()));
boolean isNeedRestore = ArrayUtils.isNotEmpty(UpdateFileUtils.listFilteredFiles(StableUtils.getInstallHome(), getBackupDirectory()));
jarRestoreLabel = isNeedRestore ? jarRestorePreviousRevision : noJarPreviousRevision;
}

40
designer-base/src/main/java/com/fr/design/update/utils/UpdateFileUtils.java

@ -0,0 +1,40 @@
package com.fr.design.update.utils;
import com.fr.stable.StableUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author Bryant
* @version 10.0
* Created by Bryant on 2020-09-25
*/
public class UpdateFileUtils {
/**
* 列出过滤后的文件
*
* @param installHome 安装目录
* @param backupdir 备份目录
* @return String数组
*/
public static String[] listFilteredFiles(String installHome, String backupdir) {
File backupDir = new File(StableUtils.pathJoin(installHome, backupdir));
StableUtils.mkdirs(backupDir);
File[] versionBackup = backupDir.listFiles();
List<String> versions = new ArrayList<>();
if (versionBackup != null) {
for (File file : versionBackup) {
if (file.isDirectory() && file.length() > 0) {
versions.add(file.getName());
} else {
StableUtils.deleteFile(file);
}
}
}
String[] result = new String[versions.size()];
return versions.toArray(result);
}
}

22
designer-base/src/test/java/com/fr/design/update/utils/UpdateFileUtilsTest.java

@ -0,0 +1,22 @@
package com.fr.design.update.utils;
import com.fr.stable.StableUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
/**
* @author Bryant
* @version 10.0
* Created by Bryant on 2020-09-25
*/
public class UpdateFileUtilsTest {
@Test
public void testListFilteredFiles() {
String[] result = UpdateFileUtils.listFilteredFiles("home", "backup");
Assert.assertEquals(0, result.length);
StableUtils.deleteFile(new File(StableUtils.pathJoin("home")));
}
}
Loading…
Cancel
Save