-
Notifications
You must be signed in to change notification settings - Fork 323
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
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f8f0c08
feat: trash
4e6 0e580d6
feat: move project to trash
4e6 8ffa14f
fix: TrashTest on Windows
4e6 b0ff163
fix: native image
4e6 569261f
Merge branch 'develop' into wip/db/10357-add-recycle
4e6 aa555cc
fix: after merge
4e6 ff4cbec
DEBUG: lazy trash initialization
4e6 3c90113
DEBUG: trash initialization
4e6 80dd6c8
DEBUG: awt initialization
4e6 df166a7
misc: javafmt
4e6 5fcd03c
misc: properties setup
4e6 efd9e05
fix: native image
4e6 bf177bf
feat: jna trash
4e6 170284b
feat: native image resources
4e6 b0d72f0
misc: cleanup properties setup
4e6 e97b44d
misc: legal review
4e6 1d296ef
Merge branch 'develop' into wip/db/10357-add-recycle
4e6 9aa46a8
fix: after merge
4e6 633f78a
Simplify LazyTrash by initializing in static initializer
JaroslavTulach e474e39
Making Platform an enum
JaroslavTulach c82ed2f
Merge branch 'develop' into wip/db/10357-add-recycle
hubertp 0d346f2
Include Jaroslav's prototype
hubertp 9066faa
os dependent
hubertp 081c9d2
fmt
hubertp 8e1e2b8
Fix native image build on linux
hubertp 5a7d9c8
Merge branch 'develop' into wip/db/10357-add-recycle
hubertp 961aa6c
remove jna
hubertp ccb8bd5
update license
hubertp 0de3f1e
nit
hubertp 2301840
fmt
hubertp 114cdca
Fix tests that broke during Platform refactoring
hubertp 20b892f
Workaround for non-AOT mode
hubertp c5aee4a
deal with non-empty directories for fallback delete
hubertp f6d66ab
fix: tests
4e6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
lib/java/desktop-environment/src/main/java/org/enso/desktopenvironment/TrashBinFallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
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) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
import org.slf4j.LoggerFactory; | ||
|
||
@CContext(WindowsTrashBin.ShellApi.class) | ||
final class WindowsTrashBin implements TrashBin { | ||
final class WindowsTrashBin extends TrashBinFallback implements TrashBin { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@CConstant | ||
public static native int FO_DELETE(); | ||
|
||
|
@@ -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; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.