toPath(FileObject fo)
and toFileObject(Path path)
utility methods.
+
* If you are running with {@code org.netbeans.modules.masterfs} enabled,
* this method should never return null for a file which exists on disk.
@@ -896,7 +926,24 @@ public static FileObject toFileObject(File file) {
}
return retVal;
}
-
+
+ /**
+ * Converts a Path to a FileObject if that is possible. It uses the
+ * {@link #toFileObject(java.io.File)} method with {@code path.toFile()}.
+ * if the conversion is not possible for some reason {@code null} is returned.
+ *
+ * @param path the {@link Path} to be converted
+ * @return the {@link FileObject} representing the {@code path} or {@code null}
+ * @since 9.32
+ */
+ public static FileObject toFileObject(Path path) {
+ try {
+ return toFileObject(path.toFile());
+ } catch (UnsupportedOperationException ex) {
+ return null;
+ }
+ }
+
/** Finds appropriate FileObjects to java.io.File if possible.
* If not possible then empty array is returned. More FileObjects may
* correspond to one java.io.File that`s why array is returned.
diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java
index 210b27f487fa..ff894afa57ec 100644
--- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java
+++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java
@@ -24,18 +24,23 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import junit.framework.Test;
+import static org.junit.Assume.assumeFalse;
import org.netbeans.junit.Log;
import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.NbTestSuite;
@@ -44,6 +49,7 @@
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor;
import org.openide.util.BaseUtilities;
+import org.openide.util.Utilities;
import org.openide.util.test.MockLookup;
/**
@@ -704,6 +710,25 @@ public void close() throws SecurityException {
assertTrue(result.toExternalForm().endsWith("/")); //NOI18N
}
+ public void testCopyPosixPerms() throws Exception {
+ assumeFalse(Utilities.isWindows());
+
+ LocalFileSystem lfs = new LocalFileSystem();
+ lfs.setRootDirectory(new File("/"));
+ FileObject workDir = lfs.findResource(getWorkDir().getAbsolutePath());
+ clearWorkDir();
+
+ FileObject source = workDir.createData("original.file");
+ Set