-
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
Conversation
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.
Unit tests are fine, but in this case, we also need some QA. Please, ensure that the deleted project can be restored (or at least seen) in the trash on all the platforms.
Assert.assertTrue(trash.moveToTrash(path)); | ||
Assert.assertFalse(trash.moveToTrash(path)); | ||
} finally { | ||
FileUtils.deleteQuietly(path.toFile()); |
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.
You can use @Rule TemporaryFolder
just like in https://github.com/enso-org/enso/blob/develop/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/exports/ExportExtensionMethodTest.java#L23 and avoid the need to delete the path yourself - JUnit runner will do that for you.
536515b
to
170284b
Compare
Update PR description:
It is out of date. |
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.
RandomUtils
seem over complicated and potentially replaceable by UUID
. Please update the PR description.
throw new IllegalArgumentException("String size should be positive."); | ||
} | ||
|
||
var random = LazyRandom.getInstance(); |
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.
Why don't we just use random = new Random()
?
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.
To initialize it once
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.
Why would you need to initialize once? For purposes of randomness, initializing again and again is completely OK unless you expect multiple random values to be needed during the same millisecond.
trashInfo, | ||
toDelete, | ||
contents, | ||
RandomUtils.alphanumericString(SUFFIX_SIZE), |
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.
It is quite common in Enso to use UUID
- which is usually created randomly based on various conditions including time seed. Is not it easier to remove RandomUtils
and just ask for UUID
?
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.
Approving changes that I haven't committed to this PR. @4e6 please review our work on SVM C's interface.
@JaroslavTulach As expected, unit tests on Windows and Mac fail because C's interface is only compiled for native image. |
NullPointerException - that's great! We could also get some Can we recover from the exception and fallback to If you want to check we run in AOT mode and only fallback to
No, rather not. |
.warn( | ||
"Moving to MacOS's Trash Bin is not supported in non-AOT mode. Deleting" | ||
+ " permanently"); | ||
return path.toFile().delete(); |
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.
It should return false
. Right now the project manager logic removes the project directory permanently if was unable to move it to trash bin.
private static final Platform OPERATING_SYSTEM = detectOperatingSystem(); | ||
|
||
/** | ||
* @GuardedBy("this") |
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.
It is not a javadoc annotation
throw new IllegalArgumentException("String size should be positive."); | ||
} | ||
|
||
var random = LazyRandom.getInstance(); |
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.
To initialize it once
|
||
@Override | ||
public boolean moveToTrash(Path path) { | ||
if (Platform.getOperatingSystem().isMacOs()) |
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.
I'd say this check is unnecessary because the class is not exposed, and its instantiation depends on the Platform.getOperatingSystem()
. I.e. the factory method guarantees the correct OS
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.
It would fail native image build otherwise.
|
||
@Override | ||
public boolean moveToTrash(Path path) { | ||
if (Platform.getOperatingSystem().isWindows()) |
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.
I'd say unnecessary, the same way as for macOS
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.
Same reason as for MacOS - native image build.
.warn( | ||
"Moving to Windows' Trash Bin is not supported in non-AOT mode. Deleting" | ||
+ " permanently"); | ||
return path.toFile().delete(); |
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.
Just return false, the project manager logic will delete the project directory permanently as a fallback action.
ifTrue = log.info("Project moved to trash [{}].", projectId), | ||
ifFalse = | ||
log.info("Failed to trash the project. Deleting [{}].", projectId) *> | ||
deleteProject *> |
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.
Here is the fallback logic that deletes the project permanently
import java.util.stream.Collectors; | ||
import org.slf4j.Logger; | ||
|
||
public class TrashBinFallback { |
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
.
public class TrashBinFallback { | |
class TrashBinFallback { |
@@ -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 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.
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.
Try sbt desktop-environment/doc
and verify it doesn't contain unnecessary elements. Otherwise good, get this in.
Windows build works correctly for me |
I don't think disabling tests for Mac and Windows was desirable. Pretty sure folks will try it in dev mode and complain that we don't delete directories. Hard delete was better. |
Hard delete will work in dev mode enso/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectService.scala Lines 158 to 163 in 73cb5d1
|
|
||
private LazyRandom() {} | ||
|
||
public static Random getInstance() { |
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.
If you really want to...
To initialize it once
... then this method is missing synchronized
modifier.
private RandomUtils() {} | ||
|
||
/** Delay the {@link Random} instance initialization when building the native image. */ | ||
private static final class LazyRandom { |
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.
Delay the {@link Random} instance initialization when building the native image.
Remove LazyRandom
class. There is no point having it.
Pull Request Description
close #10357
Changelog:
LinuxTrashBin
implementing Freedesktop.org trash specificationWindowsTrashBin
calling native platform APIs for WindowsMacTrashBin
calling native platform APIs for MacOSproject/delete
method moves projects to trash and falls back to directory deletionImportant Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.