Skip to content

Commit

Permalink
perf: warn and return if user selects home directory as container root
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Apr 23, 2024
1 parent 39f95f8 commit d7b8a6a
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.awt.Insets;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -469,6 +470,9 @@ public static String containerRootWithFormatPrefix(final String containerRoot, f
public <T extends RealType<T> & NativeType<T>, M extends N5DatasetMetadata, N extends SpatialMetadataGroup<?>> void processMultiscale()
throws IOException, InterruptedException, ExecutionException {

if (promptHomeDirectoryWarning(containerRoot))
return;

final String rootWithFormatPrefix = containerRootWithFormatPrefix(containerRoot, storageFormat, true);
if (rootWithFormatPrefix == null)
return;
Expand Down Expand Up @@ -1336,6 +1340,36 @@ private Compression getCompression() {
return getCompression(compressionArg);
}

/**
* Checks if the given path is the users' home directory. If so, prompts the user
* and returns true. Otherwise returns false.
*
* @param root the root directory
* @return false if the root path is the user's home directory
*/
private final boolean promptHomeDirectoryWarning(final String root) {

try {
final String f = new File(System.getProperty("user.home")).getCanonicalPath();
final String rootPathCanonical = new File(root).getCanonicalPath();

if (f.equals(rootPathCanonical)) {

JOptionPane.showMessageDialog(null,
"You have chosen your home directory as the container root.\n" +
"This is not allowed. Please choose a different path.\n" +
"We strongly suggest creating an empty directory.",
"Warning",
JOptionPane.WARNING_MESSAGE);

return true;
}

} catch (IOException e) {}

return false;
}

private final boolean promptOverwrite(final String dataset) {

return JOptionPane.showConfirmDialog(null,
Expand Down

0 comments on commit d7b8a6a

Please sign in to comment.