diff --git a/code/mindolph-base/src/main/java/com/mindolph/base/util/MindolphFileUtils.java b/code/mindolph-base/src/main/java/com/mindolph/base/util/MindolphFileUtils.java index 7f3742cf..ff6757b0 100644 --- a/code/mindolph-base/src/main/java/com/mindolph/base/util/MindolphFileUtils.java +++ b/code/mindolph-base/src/main/java/com/mindolph/base/util/MindolphFileUtils.java @@ -3,9 +3,11 @@ import com.mindolph.core.constant.SupportFileTypes; import com.mindolph.mfx.dialog.DialogFactory; import com.mindolph.mfx.util.DesktopUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.SystemUtils; import java.io.File; +import java.io.IOException; import java.util.Arrays; /** @@ -13,6 +15,43 @@ */ public class MindolphFileUtils { + /** + * Ignore the .DS_Store file from macOS. + * + * @param folder + * @return + * @throws IOException + */ + public static boolean isFolderEmpty(File folder) throws IOException { + if (folder == null || !folder.exists()) { + return true; + } + if (FileUtils.isEmptyDirectory(folder)) { + return true; + } + else { + String[] list = folder.list((dir, name) -> ".DS_Store".equals(name)); + return list == null || list.length == 1; + } + } + + /** + * Delete the .DS_Store file from macOS in folder. + * + * @param folder + */ + public static void deleteMacFile(File folder) { + // do not check current OS because the mac .DS_Store file might be copied to other OS. + File[] files = folder.listFiles((dir, name) -> ".DS_Store".equals(name)); + if (files != null) { + for (File file : files) { + if (file.isHidden()) { + file.delete(); + } + } + } + } + public static File getTempDir() { return new File(SystemUtils.getUserHome(), "/Temp/mindolph"); } @@ -32,6 +71,7 @@ public static File getTempFile(String fileName) { /** * TODO to be tested + * * @param filePath * @return */ diff --git a/code/mindolph-fx/src/main/java/com/mindolph/fx/view/WorkspaceView2.java b/code/mindolph-fx/src/main/java/com/mindolph/fx/view/WorkspaceView2.java index 8a3da3af..545c31b1 100644 --- a/code/mindolph-fx/src/main/java/com/mindolph/fx/view/WorkspaceView2.java +++ b/code/mindolph-fx/src/main/java/com/mindolph/fx/view/WorkspaceView2.java @@ -67,6 +67,8 @@ import java.util.*; import java.util.function.Consumer; +import static com.mindolph.base.util.MindolphFileUtils.deleteMacFile; +import static com.mindolph.base.util.MindolphFileUtils.isFolderEmpty; import static com.mindolph.core.constant.SceneStatePrefs.*; import static com.mindolph.core.constant.SupportFileTypes.*; @@ -997,7 +999,7 @@ else if (source == miClone) { else if (source == miDelete) { if (selectedData != null) { try { - if (selectedData.getFile().isDirectory() && !FileUtils.isEmptyDirectory(selectedData.getFile())) { + if (selectedData.getFile().isDirectory() && !isFolderEmpty(selectedData.getFile())) { DialogFactory.errDialog("You can not delete a folder with files."); return; } @@ -1013,6 +1015,9 @@ else if (source == miDelete) { return; } log.info("Delete file: %s".formatted(selectedData.getFile())); + if (selectedData.getFile().isDirectory()){ + deleteMacFile(selectedData.getFile()); + } try { FileUtils.delete(selectedData.getFile()); } catch (IOException e) {