Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft delete projects by moving them to trash #10440

Merged
merged 34 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f8f0c08
feat: trash
4e6 Jul 1, 2024
0e580d6
feat: move project to trash
4e6 Jul 3, 2024
8ffa14f
fix: TrashTest on Windows
4e6 Jul 4, 2024
b0ff163
fix: native image
4e6 Jul 4, 2024
569261f
Merge branch 'develop' into wip/db/10357-add-recycle
4e6 Jul 4, 2024
aa555cc
fix: after merge
4e6 Jul 4, 2024
ff4cbec
DEBUG: lazy trash initialization
4e6 Jul 5, 2024
3c90113
DEBUG: trash initialization
4e6 Jul 5, 2024
80dd6c8
DEBUG: awt initialization
4e6 Jul 5, 2024
df166a7
misc: javafmt
4e6 Jul 8, 2024
5fcd03c
misc: properties setup
4e6 Jul 8, 2024
efd9e05
fix: native image
4e6 Jul 8, 2024
bf177bf
feat: jna trash
4e6 Jul 9, 2024
170284b
feat: native image resources
4e6 Jul 9, 2024
b0d72f0
misc: cleanup properties setup
4e6 Jul 9, 2024
e97b44d
misc: legal review
4e6 Jul 9, 2024
1d296ef
Merge branch 'develop' into wip/db/10357-add-recycle
4e6 Jul 9, 2024
9aa46a8
fix: after merge
4e6 Jul 9, 2024
633f78a
Simplify LazyTrash by initializing in static initializer
JaroslavTulach Jul 21, 2024
e474e39
Making Platform an enum
JaroslavTulach Jul 21, 2024
c82ed2f
Merge branch 'develop' into wip/db/10357-add-recycle
hubertp Jul 23, 2024
0d346f2
Include Jaroslav's prototype
hubertp Jul 23, 2024
9066faa
os dependent
hubertp Jul 23, 2024
081c9d2
fmt
hubertp Jul 23, 2024
8e1e2b8
Fix native image build on linux
hubertp Jul 24, 2024
5a7d9c8
Merge branch 'develop' into wip/db/10357-add-recycle
hubertp Jul 25, 2024
961aa6c
remove jna
hubertp Jul 25, 2024
ccb8bd5
update license
hubertp Jul 25, 2024
0de3f1e
nit
hubertp Jul 25, 2024
2301840
fmt
hubertp Jul 26, 2024
114cdca
Fix tests that broke during Platform refactoring
hubertp Jul 26, 2024
20b892f
Workaround for non-AOT mode
hubertp Jul 26, 2024
c5aee4a
deal with non-empty directories for fallback delete
hubertp Jul 26, 2024
f6d66ab
fix: tests
4e6 Jul 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.slf4j.LoggerFactory;

@CContext(MacTrashBin.CoreServices.class)
final class MacTrashBin implements TrashBin {
final class MacTrashBin extends TrashBinFallback implements TrashBin {

@CFunction
static native int FSPathMakeRefWithOptions(
Expand All @@ -34,11 +34,10 @@ public boolean moveToTrash(Path path) {
return moveToTrashImpl(path);
} catch (NullPointerException | LinkageError err) {
if (!Boolean.getBoolean("com.oracle.graalvm.isaot")) {
LoggerFactory.getLogger(MacTrashBin.class)
.warn(
"Moving to MacOS's Trash Bin is not supported in non-AOT mode. Deleting"
+ " permanently");
return path.toFile().delete();
var logger = LoggerFactory.getLogger(MacTrashBin.class);
logger.warn(
"Moving to MacOS's Trash Bin is not supported in non-AOT mode. Deleting permanently");
return hardDeletePath(path, logger);
} else throw err;
}
else return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.enso.desktopenvironment;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Collectors;
import org.slf4j.Logger;

public class TrashBinFallback {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class shouldn't be public.

Suggested change
public class TrashBinFallback {
class TrashBinFallback {


protected boolean hardDeletePath(Path path, Logger logger) {
var rootFile = path.toFile();
if (rootFile.isDirectory()) {
try {
var deletedFiles =
Files.walk(path)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.map(f -> new FileDeletion(f.getPath(), f.delete()))
.filter(d -> !d.deleted())
.collect(Collectors.toList());
if (rootFile.exists()) {
logger.error(
"{} root directory failed to delete because of the following path(s):", rootFile);
deletedFiles.forEach(d -> logger.error(" - {}", d.filePath()));
return false;
}
return true;
} catch (IOException e) {
logger.error("Failed to hard delete path [{0}]", new Object[] {path, e});
return false;
}
} else {
return path.toFile().delete();
}
}

private record FileDeletion(String filePath, boolean deleted) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.slf4j.LoggerFactory;

@CContext(WindowsTrashBin.ShellApi.class)
final class WindowsTrashBin implements TrashBin {
final class WindowsTrashBin extends TrashBinFallback implements TrashBin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using inheritance for implementation purposes not for any meaningful type hierarchy. What would Lišková said about it?

I would personally make hardDeletePath a static utility method in some existing class. But if you hide all these classes from the Javadoc, then I don't care.

@CConstant
public static native int FO_DELETE();

Expand All @@ -37,11 +37,11 @@ public boolean moveToTrash(Path path) {
return moveToTrashImpl(path);
} catch (NullPointerException | LinkageError err) {
if (!Boolean.getBoolean("com.oracle.graalvm.isaot")) {
LoggerFactory.getLogger(MacTrashBin.class)
.warn(
"Moving to Windows' Trash Bin is not supported in non-AOT mode. Deleting"
+ " permanently");
return path.toFile().delete();
var logger = LoggerFactory.getLogger(MacTrashBin.class);
logger.warn(
"Moving to Windows' Trash Bin is not supported in non-AOT mode. Deleting"
+ " permanently");
return hardDeletePath(path, logger);
} else throw err;
}
else return false;
Expand Down
Loading