-
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
Changes from 18 commits
f8f0c08
0e580d6
8ffa14f
b0ff163
569261f
aa555cc
ff4cbec
3c90113
80dd6c8
df166a7
5fcd03c
efd9e05
bf177bf
170284b
b0d72f0
e97b44d
1d296ef
9aa46a8
633f78a
e474e39
c82ed2f
0d346f2
9066faa
081c9d2
8e1e2b8
5a7d9c8
961aa6c
ccb8bd5
0de3f1e
2301840
114cdca
20b892f
c5aee4a
f6d66ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,6 +537,7 @@ val directoryWatcherVersion = "0.18.0" | |
val flatbuffersVersion = "24.3.25" | ||
val guavaVersion = "32.0.0-jre" | ||
val jlineVersion = "3.23.0" | ||
val jnaVersion = "5.14.0" | ||
val jgitVersion = "6.7.0.202309050840-r" | ||
val kindProjectorVersion = "0.13.2" | ||
val mockitoScalaVersion = "1.17.14" | ||
|
@@ -1118,9 +1119,14 @@ lazy val `project-manager` = (project in file("lib/scala/project-manager")) | |
staticOnLinux = true, | ||
initializeAtRuntime = Seq( | ||
"scala.util.Random", | ||
"com.sun.jna", | ||
"zio.internal.ZScheduler$$anon$4", | ||
"zio.Runtime$", | ||
"zio.FiberRef$" | ||
), | ||
additionalOptions = Seq( | ||
"-H:+AddAllCharsets", | ||
"-H:+IncludeAllLocales" | ||
) | ||
) | ||
.dependsOn(VerifyReflectionSetup.run) | ||
|
@@ -2829,8 +2835,10 @@ lazy val `desktop-environment` = | |
.settings( | ||
frgaalJavaCompilerSetting, | ||
libraryDependencies ++= Seq( | ||
"junit" % "junit" % junitVersion % Test, | ||
"com.github.sbt" % "junit-interface" % junitIfVersion % Test | ||
"commons-io" % "commons-io" % commonsIoVersion, | ||
"net.java.dev.jna" % "jna-platform" % jnaVersion, | ||
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. Can we please write a test and make sure none of the JNA classes is visible in engine? Something like CompilerDependenciesTest but in the |
||
"junit" % "junit" % junitVersion % Test, | ||
"com.github.sbt" % "junit-interface" % junitIfVersion % Test | ||
) | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Copyright (c) 2007 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2007 Wayne Meissner, All Rights Reserved | ||
|
||
Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2007-2012 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2007-2013 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2007-2015 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2009 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2011 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2012 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2017 Matthias Bläsing, All Rights Reserved | ||
|
||
Copyright (c) 2018 Matthias Bläsing | ||
|
||
Copyright (c) 2019 Matthias Bläsing, All Rights Reserved | ||
|
||
Copyright (c) 2021, Matthias Bläsing, All Rights Reserved | ||
|
||
Copyright (c) 2022 Carlos Ballesteros, All Rights Reserved | ||
|
||
Copyright 2007 Timothy Wall |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
Copyright (c) 2007 Olivier Chafik | ||
|
||
Copyright (c) 2007 Olivier Chafik, All Rights Reserved | ||
|
||
Copyright (c) 2007 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2007, 2013 Timothy Wall, Markus Karg, All Rights Reserved | ||
|
||
Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2007-2013 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2008 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved | ||
|
||
Copyright (c) 2010 EugineLev, All Rights Reserved | ||
|
||
Copyright (c) 2010 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2010, 2013 Daniel Doubrovkine, Markus Karg, All Rights Reserved | ||
|
||
Copyright (c) 2010,2011 Daniel Doubrovkine, All Rights Reserved | ||
|
||
Copyright (c) 2011 Daniel Doubrovkine, All Rights Reserved | ||
|
||
Copyright (c) 2011 Denis Tulskiy | ||
|
||
Copyright (c) 2011 Timothy Wall, All Rights Reserved | ||
|
||
Copyright (c) 2012 Tobias Wolf, All Rights Reserved | ||
|
||
Copyright (c) 2013 Ralf Hamberger, Markus Karg, All Rights Reserved | ||
|
||
Copyright (c) 2013 Tobias Wolf, All Rights Reserved | ||
|
||
Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved | ||
|
||
Copyright (c) 2014 Reinhard Pointner, All Rights Reserved | ||
|
||
Copyright (c) 2015 Adam Marcionek, All Rights Reserved | ||
|
||
Copyright (c) 2015 Andreas "PAX" L\u00FCck, All Rights Reserved | ||
|
||
Copyright (c) 2015 Daniel Widdis | ||
|
||
Copyright (c) 2015 Goldstein Lyor, 2021 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2015 Goldstein Lyor, All Rights Reserved | ||
|
||
Copyright (c) 2015 Michael Freeman, All Rights Reserved | ||
|
||
Copyright (c) 2016 Adam Marcionek, All Rights Reserved | ||
|
||
Copyright (c) 2016 Minoru Sakamoto, All Rights Reserved | ||
|
||
Copyright (c) 2017 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2017 Matthias Bläsing, All Rights Reserved | ||
|
||
Copyright (c) 2018 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2018 Matthias Bläsing, All Rights Reserved | ||
|
||
Copyright (c) 2018 Roshan Muralidharan, All Rights Reserved | ||
|
||
Copyright (c) 2018 Václav Haisman, All Rights Reserved | ||
|
||
Copyright (c) 2018, 2021 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2018,2020,2021 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2019 Daniel Widdis | ||
|
||
Copyright (c) 2019 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2019 Keve Müller | ||
|
||
Copyright (c) 2019, 2021 Daniel Widdis | ||
|
||
Copyright (c) 2020 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2020 Torbjörn Svensson, All Rights Reserved | ||
|
||
Copyright (c) 2022 Daniel Widdis, All Rights Reserved | ||
|
||
Copyright (c) 2023 Reinhard Pointner, All Rights Reserved | ||
|
||
Copyright 2010 Digital Rapids Corp. | ||
|
||
Copyright 2014 Martin Steiger |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.enso.desktopenvironment; | ||
|
||
import com.sun.jna.platform.FileUtils; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* JNA trash implementation calling native platform-dependent APIs. | ||
* | ||
* <p>Native {@link FileUtils} are implemented for Windows and macOS platforms. | ||
*/ | ||
final class JnaTrash implements Trash { | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return FileUtils.getInstance().hasTrash(); | ||
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. Mac OS X implementation is using:
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. Maven project capable to build diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5da15f0
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apidesign.demo.trash</groupId>
+ <artifactId>Trash</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>21</maven.compiler.source>
+ <maven.compiler.target>21</maven.compiler.target>
+ <exec.mainClass>org.apidesign.demo.trash.Trash</exec.mainClass>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.graalvm.buildtools</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <version>0.10.2</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>build-native</id>
+ <goals>
+ <goal>compile-no-fork</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ <execution>
+ <id>test-native</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.apidesign.demo.trash.Trash</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/src/main/java/org/apidesign/demo/trash/Trash.java b/src/main/java/org/apidesign/demo/trash/Trash.java
new file mode 100644
index 0000000..d69262c
--- /dev/null
+++ b/src/main/java/org/apidesign/demo/trash/Trash.java
@@ -0,0 +1,35 @@
+package org.apidesign.demo.trash;
+
+import org.graalvm.nativeimage.UnmanagedMemory;
+import org.graalvm.nativeimage.c.function.CFunction;
+import org.graalvm.nativeimage.c.function.CLibrary;
+import org.graalvm.nativeimage.c.type.CCharPointer;
+import org.graalvm.nativeimage.c.type.CTypeConversion;
+import org.graalvm.word.Pointer;
+import org.graalvm.word.WordFactory;
+
+@CLibrary("-framework CoreServices")
+public class Trash {
+
+ public static void main(String[] args) {
+ System.out.println("Moving " + args[0] + " to trash");
+ Pointer ref = WordFactory.nullPointer();
+ Pointer source = UnmanagedMemory.malloc(80);
+ Pointer target = UnmanagedMemory.malloc(80);
+
+ var kFSPathMakeRefDoNotFollowLeafSymlink = 0x01;
+ var kFSFileOperationDefaultOptions = 0x00;
+ try (var path = CTypeConversion.toCString(args[0])) {
+ var r1 = FSPathMakeRefWithOptions(path.get(), kFSPathMakeRefDoNotFollowLeafSymlink, source, ref);
+ System.err.println("result one: " + r1);
+ var r2 = FSMoveObjectToTrashSync(source, target, kFSFileOperationDefaultOptions);
+ System.err.println("result two: " + r2);
+ }
+ }
+
+ @CFunction
+ static native int FSPathMakeRefWithOptions(CCharPointer path, int flags, Pointer buffer, Pointer any);
+
+ @CFunction
+ static native int FSMoveObjectToTrashSync(Pointer source, Pointer target, int flags);
+} 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. Improved version that also conditionally enables itself only on Mac: package org.apidesign.demo.trash;
import java.util.Arrays;
import java.util.List;
import org.graalvm.nativeimage.UnmanagedMemory;
import org.graalvm.nativeimage.c.CContext;
import org.graalvm.nativeimage.c.constant.CConstant;
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.graalvm.word.Pointer;
import org.graalvm.word.WordFactory;
@CContext(Trash.CoreServices.class)
public class Trash {
public static void main(String[] args) {
System.out.println("Moving " + args[0] + " to trash");
Pointer ref = WordFactory.nullPointer();
Pointer source = UnmanagedMemory.malloc(80);
Pointer target = UnmanagedMemory.malloc(80);
try (var path = CTypeConversion.toCString(args[0])) {
var r1 = FSPathMakeRefWithOptions(path.get(), kFSPathMakeRefDoNotFollowLeafSymlink(), source, ref);
System.err.println("result one: " + r1);
var r2 = FSMoveObjectToTrashSync(source, target, kFSFileOperationDefaultOptions());
System.err.println("result two: " + r2);
}
UnmanagedMemory.free(source);
UnmanagedMemory.free(target);
}
@CConstant
static native int kFSPathMakeRefDoNotFollowLeafSymlink();
@CConstant
static native int kFSFileOperationDefaultOptions();
@CFunction
static native int FSPathMakeRefWithOptions(CCharPointer path, int flags, Pointer buffer, Pointer any);
@CFunction
static native int FSMoveObjectToTrashSync(Pointer source, Pointer target, int flags);
public static final class CoreServices implements CContext.Directives {
@Override
public boolean isInConfiguration() {
return System.getProperty("os.name").contains("Mac");
}
@Override
public List<String> getHeaderFiles() {
return Arrays.asList("<CoreServices/CoreServices.h>");
}
@Override
public List<String> getLibraries() {
return Arrays.asList("-framework CoreServices");
}
}
} |
||
} | ||
|
||
@Override | ||
public boolean moveToTrash(Path path) { | ||
if (Files.exists(path) && isSupported()) { | ||
try { | ||
FileUtils.getInstance().moveToTrash(path.toFile()); | ||
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. The Windows implementation is defined at W32FileUtils and it seems to call into: 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. Implementation of move to trash for Windows: diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..c5d905e
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apidesign.demo</groupId>
+ <artifactId>trash</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>21</maven.compiler.source>
+ <maven.compiler.target>21</maven.compiler.target>
+ <exec.mainClass>org.apidesign.demo.trash.Trash</exec.mainClass>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.graalvm.buildtools</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <version>0.10.2</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>build-native</id>
+ <goals>
+ <goal>compile-no-fork</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ <execution>
+ <id>test-native</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.apidesign.demo.trash.Trash</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/src/main/java/org/apidesign/demo/trash/Trash.java b/src/main/java/org/apidesign/demo/trash/Trash.java
new file mode 100644
index 0000000..1a536b0
--- /dev/null
+++ b/src/main/java/org/apidesign/demo/trash/Trash.java
@@ -0,0 +1,64 @@
+package org.apidesign.demo.trash;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.graalvm.nativeimage.StackValue;
+import org.graalvm.nativeimage.c.CContext;
+import org.graalvm.nativeimage.c.constant.CConstant;
+import org.graalvm.nativeimage.c.function.CFunction;
+import org.graalvm.nativeimage.c.struct.CField;
+import org.graalvm.nativeimage.c.struct.CStruct;
+import org.graalvm.nativeimage.c.type.CCharPointer;
+import org.graalvm.nativeimage.c.type.CTypeConversion;
+import org.graalvm.word.PointerBase;
+
+@CContext(Trash.ShellApi.class)
+public class Trash {
+
+ public static void main(String[] args) {
+ System.out.println("Moving " + args[0] + " to trash");
+ try (var file = CTypeConversion.toCString(args[0] + "\0")) {
+ var fileop = StackValue.get(SHFileOperation.class);
+ fileop.wFunc(FO_DELETE());
+ fileop.pFrom(file.get());
+ fileop.fFlags((short) (FOF_ALLOWUNDO() | FOF_NO_UI()));
+ var res = SHFileOperationA(fileop);
+ System.out.println("res: 0x" + Integer.toHexString(res));
+ }
+ }
+
+ @CConstant
+ public static native int FO_DELETE();
+ @CConstant
+ public static native int FOF_ALLOWUNDO();
+ @CConstant
+ public static native int FOF_NO_UI();
+
+ @CStruct(value="SHFILEOPSTRUCTA")
+ static interface SHFileOperation extends PointerBase {
+ @CField
+ void pFrom(CCharPointer from);
+ @CField
+ void wFunc(int op);
+ @CField
+ void fFlags(short flags);
+ }
+
+ @CFunction
+ static native int SHFileOperationA(SHFileOperation fileop);
+
+ public static final class ShellApi implements CContext.Directives {
+
+ @Override
+ public List<String> getHeaderFiles() {
+ return Arrays.asList("<windows.h>");
+ }
+
+ @Override
+ public List<String> getLibraries() {
+ return Arrays.asList("shell32");
+ }
+
+ }
+} |
||
|
||
return true; | ||
} catch (IOException ignored) { | ||
return false; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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.
Adding JNA just get location of thrashbin on Mac and Windows seems like an overkill to me. As far as I know JNA needs a
.so
or.dll
library to work and it first of all unpacks it to/tmp
directory and then loads it. I am even surprised this process works in SVM.