From 7031286da30568563fea481c703c9392d0093ac1 Mon Sep 17 00:00:00 2001 From: umjammer Date: Sat, 30 May 2020 07:32:54 +0900 Subject: [PATCH 01/13] separate into sub modules --- DropBoxFS.java | 54 +++++++++++++++++++++++ Main.java | 61 ++++++++++++++++++++++++++ Main3.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 DropBoxFS.java create mode 100644 Main.java create mode 100644 Main3.java diff --git a/DropBoxFS.java b/DropBoxFS.java new file mode 100644 index 0000000..372767a --- /dev/null +++ b/DropBoxFS.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +package vavi.nio.file.dropbox; + +import java.net.URI; +import java.nio.file.FileSystem; +import java.util.HashMap; +import java.util.Map; + +import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; + +import vavi.net.auth.oauth2.OAuth2AppCredential; +import vavi.net.auth.oauth2.dropbox.DropBoxLocalAppCredential; +import vavi.net.fuse.JavaFsFS; +import vavi.util.properties.annotation.PropsEntity; + + +/** + * DropBoxFS. (fuse-jna) + * + * @author Naohide Sano (umjammer) + * @version 0.00 2016/03/02 umjammer initial version
+ */ +public class DropBoxFS { + + /** + * @param args 0: mount point, 1: email + */ + public static void main(String[] args) throws Exception { + if (args.length != 2) { + System.err.println("Usage: DropBoxFS "); + System.exit(1); + } + + String email = args[1]; + + URI uri = URI.create("dropbox:///?id=" + email); + + OAuth2AppCredential appCredential = new DropBoxLocalAppCredential(); + PropsEntity.Util.bind(appCredential); + + Map env = new HashMap<>(); + env.put(DropBoxFileSystemProvider.ENV_APP_CREDENTIAL, appCredential); + env.put("ignoreAppleDouble", true); + + FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); + + new JavaFsFS(fs).mount(args[0]); + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..7e0dc25 --- /dev/null +++ b/Main.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +package vavi.nio.file.dropbox; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; + +import static vavi.nio.file.Base.testAll; + +import co.paralleluniverse.javafs.JavaFS; + + +/** + * Main. (java fs, dropbox) + * + * @author Naohide Sano (umjammer) + * @version 0.00 2019/07/11 umjammer initial version
+ */ +public class Main { + + /** + * @param args 0: mount point, 1: email + */ + public static void main(final String... args) throws IOException { + String email = args[1]; + + Map env = new HashMap<>(); + env.put("ignoreAppleDouble", true); + + URI uri = URI.create("dropbox:///?id=" + email); + + FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); + + Map options = new HashMap<>(); + options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); + + JavaFS.mount(fs, Paths.get(args[0]), false, true, options); + } + + @Test + void test01() throws Exception { + String email = System.getenv("DROPBOX_TEST_ACCOUNT"); + + URI uri = URI.create("dropbox:///?id=" + email); + + testAll(new DropBoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP)); + } +} \ No newline at end of file diff --git a/Main3.java b/Main3.java new file mode 100644 index 0000000..1470377 --- /dev/null +++ b/Main3.java @@ -0,0 +1,117 @@ + +package vavi.nio.file.dropbox; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashMap; +import java.util.Map; + +import vavi.util.properties.annotation.Property; +import vavi.util.properties.annotation.PropsEntity; + +import static java.nio.file.FileVisitResult.CONTINUE; + + +/** + * dropbox nio walk. + * + * @author Naohide Sano (umjammer) + * @version 0.00 2016/03/21 umjammer initial version
+ */ +@PropsEntity(url = "file://${HOME}/.vavifuse/dropbox/{0}") +public final class Main3 { + + @Property(name = "dropbox.accessToken") + private String accessToken; + + public static void main(final String... args) throws IOException { + String email = args[0]; + + Main3 app = new Main3(); + PropsEntity.Util.bind(app, email); + + // Create the necessary elements to create a filesystem. + // Note: the URI _must_ have a scheme of "dropbox", and + // _must_ be hierarchical. + URI uri = URI.create("dropbox:///"); + + final Map env = new HashMap<>(); + env.put("accessToken", app.accessToken); + + // Create the filesystem... + try (FileSystem dropboxfs = FileSystems.newFileSystem(uri, env)) { + + // And use it! You should of course adapt this code... + // Equivalent to FileSystems.getDefault().getPath(...) + final Path src = Paths.get(System.getProperty("user.home") + "/tmp/2" , "java7.java"); + // Here we create a path for our DropBox fs... + final Path dst = dropboxfs.getPath("/java7.java"); + // Here we copy the file from our local fs to dropbox! + try { +System.out.println("$ list"); + Files.list(dst.getParent()).forEach(System.out::println); +System.out.println("$ copy"); + Files.copy(src, dst); + } catch (FileAlreadyExistsException e) { +//e.printStackTrace(System.out); +System.err.println(e); +System.out.println("$ delete"); + Files.delete(dst); +System.out.println("$ list"); + Files.list(dst.getParent()).forEach(System.out::println); +System.out.println("$ copy"); + Files.copy(src, dst); + } + System.out.println("$ list"); +Files.list(dst.getParent()).forEach(System.out::println); + +// Path root = dropboxfs.getRootDirectories().iterator().next(); +// Files.walkFileTree(root, new PrintFiles()); + } + } + + static class PrintFiles extends SimpleFileVisitor { + + // Print information about + // each type of file. + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { + if (attr.isSymbolicLink()) { + System.out.format("Symbolic link: %s ", file); + } else if (attr.isRegularFile()) { + System.out.format("Regular file : %s ", file); + } else { + System.out.format("Other : %s ", file); + } + System.out.println("(" + attr.size() + "bytes)"); + return CONTINUE; + } + + // Print each directory visited. + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) { + System.out.format("Directory : %s%n", dir); + return CONTINUE; + } + + // If there is some error accessing + // the file, let the user know. + // If you don't override this method + // and an error occurs, an IOException + // is thrown. + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + System.err.println(exc); + return CONTINUE; + } + } +} From 3216208bdb22d3a533bebdecc13c27a57d95cdfe Mon Sep 17 00:00:00 2001 From: umjammer Date: Sat, 30 May 2020 07:40:48 +0900 Subject: [PATCH 02/13] update about gathered fs --- DropBoxFS.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DropBoxFS.java b/DropBoxFS.java index 372767a..969e8e7 100644 --- a/DropBoxFS.java +++ b/DropBoxFS.java @@ -8,6 +8,7 @@ import java.net.URI; import java.nio.file.FileSystem; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -15,7 +16,7 @@ import vavi.net.auth.oauth2.OAuth2AppCredential; import vavi.net.auth.oauth2.dropbox.DropBoxLocalAppCredential; -import vavi.net.fuse.JavaFsFS; +import vavi.net.fuse.Fuse; import vavi.util.properties.annotation.PropsEntity; @@ -49,6 +50,6 @@ public static void main(String[] args) throws Exception { FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); - new JavaFsFS(fs).mount(args[0]); + Fuse.Factory.getFuse().mount(fs, args[0], Collections.EMPTY_MAP); } } From 21ce9268911cab891f99a9a6d0170b587c57043d Mon Sep 17 00:00:00 2001 From: umjammer Date: Thu, 4 Jun 2020 11:14:50 +0900 Subject: [PATCH 03/13] make those fuse compliant --- DropBoxFS.java | 2 +- Main4.java | 177 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 Main4.java diff --git a/DropBoxFS.java b/DropBoxFS.java index 969e8e7..656b380 100644 --- a/DropBoxFS.java +++ b/DropBoxFS.java @@ -50,6 +50,6 @@ public static void main(String[] args) throws Exception { FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); - Fuse.Factory.getFuse().mount(fs, args[0], Collections.EMPTY_MAP); + Fuse.getFuse().mount(fs, args[0], Collections.EMPTY_MAP); } } diff --git a/Main4.java b/Main4.java new file mode 100644 index 0000000..b5f5126 --- /dev/null +++ b/Main4.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2017 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +package vavi.nio.file.dropbox; + +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; + +import vavi.net.fuse.Fuse; +import vavi.util.Debug; + +import vavix.util.Checksum; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +/** + * Main4. (fuse) + * + * @author Naohide Sano (umjammer) + * @version 0.00 2017/03/19 umjammer initial version
+ */ +@DisabledIfEnvironmentVariable(named = "GITHUB_WORKFLOW", matches = ".*") +public class Main4 { + + static Fuse fuse; + static String mountPoint; + static FileSystem fs; + + @BeforeAll + public static void before() throws Exception { + System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", "co\\.paralleluniverse\\.fuse\\.LoggedFuseFilesystem#log"); + + System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); +// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); + + String email = System.getenv("TEST4_ACCOUNT"); + mountPoint = System.getenv("TEST4_MOUNT_POINT"); + + URI uri = URI.create("dropbox:///?id=" + email); + + Map env = new HashMap<>(); + env.put("ignoreAppleDouble", true); + + fs = FileSystems.newFileSystem(uri, env); + + Map options = new HashMap<>(); + options.put("fsname", "googledrive_fs" + "@" + System.currentTimeMillis()); + options.put("noappledouble", null); + //options.put("noapplexattr", null); + options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_DEBUG, false); + options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_READ_ONLY, false); + + fuse = Fuse.getFuse(); + fuse.mount(fs, mountPoint, options); + } + + /** */ + private int exec(String... commandLine) throws Exception { + ProcessBuilder processBuilder = new ProcessBuilder(commandLine); + processBuilder.inheritIO(); + Process process = processBuilder.start(); + process.waitFor(); + return process.exitValue(); + } + + /** + * create + * write + * chmod + * chmod + * chmod + * flush + * lock + * release + */ + @Test + public void testCopyFromLocalToTarget() throws Exception { + Path from = Paths.get("src/test/resources/Hello.java"); + Path toDir = Paths.get(mountPoint, "VAVI_FUSE_TEST4"); + if (!Files.exists(toDir)) { +Debug.println("[mkdir] " + toDir); + assertEquals(0, exec("/bin/mkdir", toDir.toString())); + } + Path to = toDir.resolve(from.getFileName()); + if (Files.exists(to)) { +Debug.println("[rm] " + to); + assertEquals(0, exec("/bin/rm", to.toString())); + } +Debug.println("[cp] " + from + " " + to); + assertEquals(0, exec("/bin/cp", from.toString(), to.toString())); + assertEquals(0, exec("/bin/ls", "-l", to.toString())); + assertEquals(0, exec("/bin/ls", "-l", from.toString())); + assertTrue(Files.exists(to)); + assertEquals(Files.size(from), Files.size(to)); + assertEquals(Checksum.getChecksum(from), Checksum.getChecksum(to)); + Debug.println("[rm] " + to); + assertEquals(0, exec("/bin/rm", to.toString())); +Debug.println("[rmdir] " + toDir); + assertEquals(0, exec("/bin/rmdir", toDir.toString())); + assertFalse(Files.exists(to)); + assertFalse(Files.exists(toDir)); + } + + /** + * open + * read + * flush + * lock + * release + */ + @Test + public void testCopyFromRemoteToTarget() throws Exception { + Path from = Paths.get("src/test/resources/Hello.java"); + Path remoteDir = fs.getPath("/VAVI_FUSE_TEST4"); + if (!Files.exists(remoteDir)) { +Debug.println("[_mkdir] " + remoteDir); + Files.createDirectory(remoteDir); + } + Path remote = remoteDir.resolve(from.getFileName().toString()); +Debug.println("[_cp] " + from + " " + remote); + Files.copy(from, remote, StandardCopyOption.REPLACE_EXISTING); + assertTrue(Files.exists(remote)); + + Path toDir = Paths.get("tmp"); + if (!Files.exists(toDir)) { +Debug.println("[_mkdir] " + toDir); + Files.createDirectory(toDir); + } + Path fuseDir = Paths.get(mountPoint, remoteDir.getFileName().toString()); + Path fuse = fuseDir.resolve(remote.getFileName().toString()); + Path to = toDir.resolve(fuse.getFileName().toString()); + if (Files.exists(to)) { +Debug.println("[_rm] " + to); + Files.delete(to); + } +Debug.println("[cp] " + fuse + " " + to); + assertEquals(0, exec("/bin/cp", fuse.toString(), to.toString())); + assertEquals(0, exec("/bin/ls", "-l", fuseDir.toString())); + assertEquals(0, exec("/bin/ls", "-l", to.toString())); + assertTrue(Files.exists(to)); + assertEquals(Files.size(fuse), Files.size(to)); + assertEquals(Checksum.getChecksum(fuse), Checksum.getChecksum(to)); +Debug.println("[rm] " + remote); + assertEquals(0, exec("/bin/rm", fuse.toString())); +Debug.println("[rmdir] " + toDir); + assertEquals(0, exec("/bin/rmdir", fuseDir.toString())); + assertFalse(Files.exists(fuse)); + assertFalse(Files.exists(fuseDir)); + } + + @AfterAll + public static void after() throws Exception { +Debug.println("unmount: start"); + fuse.close(); +Debug.println("unmount: done"); + } +} + +/* */ From 921a713beae1390c1f156ad54b70669c904d8acf Mon Sep 17 00:00:00 2001 From: umjammer Date: Fri, 5 Jun 2020 18:07:13 +0900 Subject: [PATCH 04/13] remove redundancies --- Main4.java | 146 ++++++++--------------------------------------------- 1 file changed, 21 insertions(+), 125 deletions(-) diff --git a/Main4.java b/Main4.java index b5f5126..8815442 100644 --- a/Main4.java +++ b/Main4.java @@ -9,26 +9,15 @@ import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import vavi.net.fuse.Fuse; -import vavi.util.Debug; - -import vavix.util.Checksum; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import vavi.net.fuse.Base; /** @@ -40,17 +29,14 @@ @DisabledIfEnvironmentVariable(named = "GITHUB_WORKFLOW", matches = ".*") public class Main4 { - static Fuse fuse; - static String mountPoint; - static FileSystem fs; + String mountPoint; + FileSystem fs; + Map options; - @BeforeAll - public static void before() throws Exception { + @BeforeEach + public void before() throws Exception { System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", "co\\.paralleluniverse\\.fuse\\.LoggedFuseFilesystem#log"); - System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); - String email = System.getenv("TEST4_ACCOUNT"); mountPoint = System.getenv("TEST4_MOUNT_POINT"); @@ -61,116 +47,26 @@ public static void before() throws Exception { fs = FileSystems.newFileSystem(uri, env); - Map options = new HashMap<>(); - options.put("fsname", "googledrive_fs" + "@" + System.currentTimeMillis()); + options = new HashMap<>(); + options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); options.put("noappledouble", null); //options.put("noapplexattr", null); options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_DEBUG, false); options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_READ_ONLY, false); - - fuse = Fuse.getFuse(); - fuse.mount(fs, mountPoint, options); } - /** */ - private int exec(String... commandLine) throws Exception { - ProcessBuilder processBuilder = new ProcessBuilder(commandLine); - processBuilder.inheritIO(); - Process process = processBuilder.start(); - process.waitFor(); - return process.exitValue(); - } - - /** - * create - * write - * chmod - * chmod - * chmod - * flush - * lock - * release - */ - @Test - public void testCopyFromLocalToTarget() throws Exception { - Path from = Paths.get("src/test/resources/Hello.java"); - Path toDir = Paths.get(mountPoint, "VAVI_FUSE_TEST4"); - if (!Files.exists(toDir)) { -Debug.println("[mkdir] " + toDir); - assertEquals(0, exec("/bin/mkdir", toDir.toString())); - } - Path to = toDir.resolve(from.getFileName()); - if (Files.exists(to)) { -Debug.println("[rm] " + to); - assertEquals(0, exec("/bin/rm", to.toString())); - } -Debug.println("[cp] " + from + " " + to); - assertEquals(0, exec("/bin/cp", from.toString(), to.toString())); - assertEquals(0, exec("/bin/ls", "-l", to.toString())); - assertEquals(0, exec("/bin/ls", "-l", from.toString())); - assertTrue(Files.exists(to)); - assertEquals(Files.size(from), Files.size(to)); - assertEquals(Checksum.getChecksum(from), Checksum.getChecksum(to)); - Debug.println("[rm] " + to); - assertEquals(0, exec("/bin/rm", to.toString())); -Debug.println("[rmdir] " + toDir); - assertEquals(0, exec("/bin/rmdir", toDir.toString())); - assertFalse(Files.exists(to)); - assertFalse(Files.exists(toDir)); - } + @ParameterizedTest + @ValueSource(strings = { + "vavi.net.fuse.javafs.JavaFSFuseProvider", + "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider", + "vavi.net.fuse.fusejna.FuseJnaFuseProvider", + }) + public void test01(String providerClassName) throws Exception { + System.setProperty("vavi.net.fuse.FuseProvider.class", providerClassName); - /** - * open - * read - * flush - * lock - * release - */ - @Test - public void testCopyFromRemoteToTarget() throws Exception { - Path from = Paths.get("src/test/resources/Hello.java"); - Path remoteDir = fs.getPath("/VAVI_FUSE_TEST4"); - if (!Files.exists(remoteDir)) { -Debug.println("[_mkdir] " + remoteDir); - Files.createDirectory(remoteDir); - } - Path remote = remoteDir.resolve(from.getFileName().toString()); -Debug.println("[_cp] " + from + " " + remote); - Files.copy(from, remote, StandardCopyOption.REPLACE_EXISTING); - assertTrue(Files.exists(remote)); - - Path toDir = Paths.get("tmp"); - if (!Files.exists(toDir)) { -Debug.println("[_mkdir] " + toDir); - Files.createDirectory(toDir); - } - Path fuseDir = Paths.get(mountPoint, remoteDir.getFileName().toString()); - Path fuse = fuseDir.resolve(remote.getFileName().toString()); - Path to = toDir.resolve(fuse.getFileName().toString()); - if (Files.exists(to)) { -Debug.println("[_rm] " + to); - Files.delete(to); - } -Debug.println("[cp] " + fuse + " " + to); - assertEquals(0, exec("/bin/cp", fuse.toString(), to.toString())); - assertEquals(0, exec("/bin/ls", "-l", fuseDir.toString())); - assertEquals(0, exec("/bin/ls", "-l", to.toString())); - assertTrue(Files.exists(to)); - assertEquals(Files.size(fuse), Files.size(to)); - assertEquals(Checksum.getChecksum(fuse), Checksum.getChecksum(to)); -Debug.println("[rm] " + remote); - assertEquals(0, exec("/bin/rm", fuse.toString())); -Debug.println("[rmdir] " + toDir); - assertEquals(0, exec("/bin/rmdir", fuseDir.toString())); - assertFalse(Files.exists(fuse)); - assertFalse(Files.exists(fuseDir)); - } + Base.testFuse(fs, mountPoint, options); - @AfterAll - public static void after() throws Exception { -Debug.println("unmount: start"); - fuse.close(); -Debug.println("unmount: done"); + fs.close(); } } From 02a47f9c2d339edf1e89b0de9d27d41671a1c333 Mon Sep 17 00:00:00 2001 From: umjammer Date: Fri, 5 Jun 2020 18:11:31 +0900 Subject: [PATCH 05/13] add dealing large file functionality --- Main2.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Main2.java diff --git a/Main2.java b/Main2.java new file mode 100644 index 0000000..79ed239 --- /dev/null +++ b/Main2.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 by Naohide Sano, All rights reserved. + * + * Programmed by Naohide Sano + */ + +package vavi.nio.file.dropbox; + +import java.net.URI; +import java.nio.file.FileSystem; +import java.util.Collections; + +import org.junit.jupiter.api.Test; + +import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; + +import static vavi.nio.file.Base.testLargeFile; + + +/** + * DropBox. (v2) + * + * @author Naohide Sano (umjammer) + * @version 0.00 2016/03/xx umjammer initial version
+ */ +public class Main2 { + + @Test + void test01() throws Exception { + String email = System.getenv("DROPBOX_TEST_ACCOUNT"); + + URI uri = URI.create("dropbox:///?id=" + email); + FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); + + testLargeFile(fs, null); + } +} \ No newline at end of file From 5b53642ee2c869f598bad070428b58393c32bfe7 Mon Sep 17 00:00:00 2001 From: umjammer Date: Wed, 10 Jun 2020 17:53:07 +0900 Subject: [PATCH 06/13] update about dropbox test --- Main.java | 26 -------------------------- Main4.java | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Main.java b/Main.java index 7e0dc25..3770fa8 100644 --- a/Main.java +++ b/Main.java @@ -6,13 +6,8 @@ package vavi.nio.file.dropbox; -import java.io.IOException; import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.Paths; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import org.junit.jupiter.api.Test; @@ -20,8 +15,6 @@ import static vavi.nio.file.Base.testAll; -import co.paralleluniverse.javafs.JavaFS; - /** * Main. (java fs, dropbox) @@ -31,25 +24,6 @@ */ public class Main { - /** - * @param args 0: mount point, 1: email - */ - public static void main(final String... args) throws IOException { - String email = args[1]; - - Map env = new HashMap<>(); - env.put("ignoreAppleDouble", true); - - URI uri = URI.create("dropbox:///?id=" + email); - - FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); - - Map options = new HashMap<>(); - options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); - - JavaFS.mount(fs, Paths.get(args[0]), false, true, options); - } - @Test void test01() throws Exception { String email = System.getenv("DROPBOX_TEST_ACCOUNT"); diff --git a/Main4.java b/Main4.java index 8815442..e105156 100644 --- a/Main4.java +++ b/Main4.java @@ -6,9 +6,11 @@ package vavi.nio.file.dropbox; +import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -17,8 +19,12 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; + import vavi.net.fuse.Base; +import co.paralleluniverse.javafs.JavaFS; + /** * Main4. (fuse) @@ -68,6 +74,27 @@ public void test01(String providerClassName) throws Exception { fs.close(); } + + // + + /** + * @param args 0: mount point, 1: email + */ + public static void main(final String... args) throws IOException { + String email = args[1]; + + Map env = new HashMap<>(); + env.put("ignoreAppleDouble", true); + + URI uri = URI.create("dropbox:///?id=" + email); + + FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); + + Map options = new HashMap<>(); + options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); + + JavaFS.mount(fs, Paths.get(args[0]), false, true, options); + } } /* */ From bdb81942eda1426c7ecf18a97fadbc2895c969eb Mon Sep 17 00:00:00 2001 From: umjammer Date: Thu, 18 Jun 2020 05:17:40 +0900 Subject: [PATCH 07/13] =?UTF-8?q?=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Main4.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Main4.java b/Main4.java index e105156..35c54e0 100644 --- a/Main4.java +++ b/Main4.java @@ -27,7 +27,7 @@ /** - * Main4. (fuse) + * fuse test. (dropbox) * * @author Naohide Sano (umjammer) * @version 0.00 2017/03/19 umjammer initial version
From f50f93c6e145d99f9ad78156ff7f2aa58bf3434d Mon Sep 17 00:00:00 2001 From: umjammer Date: Fri, 19 Jun 2020 17:43:29 +0900 Subject: [PATCH 08/13] follow dropbox flatten packages --- DropBoxFS.java | 2 +- Main.java | 2 +- Main2.java | 2 +- Main4.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DropBoxFS.java b/DropBoxFS.java index 656b380..0e73cbb 100644 --- a/DropBoxFS.java +++ b/DropBoxFS.java @@ -12,7 +12,7 @@ import java.util.HashMap; import java.util.Map; -import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; +import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; import vavi.net.auth.oauth2.OAuth2AppCredential; import vavi.net.auth.oauth2.dropbox.DropBoxLocalAppCredential; diff --git a/Main.java b/Main.java index 3770fa8..26ac3d0 100644 --- a/Main.java +++ b/Main.java @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test; -import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; +import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; import static vavi.nio.file.Base.testAll; diff --git a/Main2.java b/Main2.java index 79ed239..9f719b9 100644 --- a/Main2.java +++ b/Main2.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; -import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; +import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; import static vavi.nio.file.Base.testLargeFile; diff --git a/Main4.java b/Main4.java index 35c54e0..0f58ee5 100644 --- a/Main4.java +++ b/Main4.java @@ -19,7 +19,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import com.github.fge.fs.dropbox.provider.DropBoxFileSystemProvider; +import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; import vavi.net.fuse.Base; From d7133205e4b73c730aca1cc240f2be1bd8d86554 Mon Sep 17 00:00:00 2001 From: umjammer Date: Fri, 19 Jun 2020 17:52:27 +0900 Subject: [PATCH 09/13] clean up code --- DropBoxFS.java | 5 +++-- Main4.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DropBoxFS.java b/DropBoxFS.java index 0e73cbb..71ed764 100644 --- a/DropBoxFS.java +++ b/DropBoxFS.java @@ -17,7 +17,6 @@ import vavi.net.auth.oauth2.OAuth2AppCredential; import vavi.net.auth.oauth2.dropbox.DropBoxLocalAppCredential; import vavi.net.fuse.Fuse; -import vavi.util.properties.annotation.PropsEntity; /** @@ -42,7 +41,9 @@ public static void main(String[] args) throws Exception { URI uri = URI.create("dropbox:///?id=" + email); OAuth2AppCredential appCredential = new DropBoxLocalAppCredential(); - PropsEntity.Util.bind(appCredential); + +// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); +// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); Map env = new HashMap<>(); env.put(DropBoxFileSystemProvider.ENV_APP_CREDENTIAL, appCredential); diff --git a/Main4.java b/Main4.java index 0f58ee5..aab5ddd 100644 --- a/Main4.java +++ b/Main4.java @@ -90,6 +90,9 @@ public static void main(final String... args) throws IOException { FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); +// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); +// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); + Map options = new HashMap<>(); options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); From 2532ca14b4806a49418ddf5088817f94a5edfb3d Mon Sep 17 00:00:00 2001 From: umjammer Date: Fri, 19 Jun 2020 23:04:35 +0900 Subject: [PATCH 10/13] update folder move functionality --- Main3.java | 108 +++++++---------------------------------------------- 1 file changed, 13 insertions(+), 95 deletions(-) diff --git a/Main3.java b/Main3.java index 1470377..082f560 100644 --- a/Main3.java +++ b/Main3.java @@ -1,28 +1,21 @@ package vavi.nio.file.dropbox; -import java.io.IOException; import java.net.URI; -import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.HashMap; -import java.util.Map; +import java.util.Collections; + +import org.junit.jupiter.api.Test; + +import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; -import vavi.util.properties.annotation.Property; import vavi.util.properties.annotation.PropsEntity; -import static java.nio.file.FileVisitResult.CONTINUE; +import static vavi.nio.file.Base.testMoveFolder; /** - * dropbox nio walk. + * dropbox move folder. * * @author Naohide Sano (umjammer) * @version 0.00 2016/03/21 umjammer initial version
@@ -30,88 +23,13 @@ @PropsEntity(url = "file://${HOME}/.vavifuse/dropbox/{0}") public final class Main3 { - @Property(name = "dropbox.accessToken") - private String accessToken; - - public static void main(final String... args) throws IOException { - String email = args[0]; - - Main3 app = new Main3(); - PropsEntity.Util.bind(app, email); - - // Create the necessary elements to create a filesystem. - // Note: the URI _must_ have a scheme of "dropbox", and - // _must_ be hierarchical. - URI uri = URI.create("dropbox:///"); - - final Map env = new HashMap<>(); - env.put("accessToken", app.accessToken); - - // Create the filesystem... - try (FileSystem dropboxfs = FileSystems.newFileSystem(uri, env)) { - - // And use it! You should of course adapt this code... - // Equivalent to FileSystems.getDefault().getPath(...) - final Path src = Paths.get(System.getProperty("user.home") + "/tmp/2" , "java7.java"); - // Here we create a path for our DropBox fs... - final Path dst = dropboxfs.getPath("/java7.java"); - // Here we copy the file from our local fs to dropbox! - try { -System.out.println("$ list"); - Files.list(dst.getParent()).forEach(System.out::println); -System.out.println("$ copy"); - Files.copy(src, dst); - } catch (FileAlreadyExistsException e) { -//e.printStackTrace(System.out); -System.err.println(e); -System.out.println("$ delete"); - Files.delete(dst); -System.out.println("$ list"); - Files.list(dst.getParent()).forEach(System.out::println); -System.out.println("$ copy"); - Files.copy(src, dst); - } - System.out.println("$ list"); -Files.list(dst.getParent()).forEach(System.out::println); - -// Path root = dropboxfs.getRootDirectories().iterator().next(); -// Files.walkFileTree(root, new PrintFiles()); - } - } - - static class PrintFiles extends SimpleFileVisitor { - - // Print information about - // each type of file. - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { - if (attr.isSymbolicLink()) { - System.out.format("Symbolic link: %s ", file); - } else if (attr.isRegularFile()) { - System.out.format("Regular file : %s ", file); - } else { - System.out.format("Other : %s ", file); - } - System.out.println("(" + attr.size() + "bytes)"); - return CONTINUE; - } + @Test + void test01() throws Exception { + String email = System.getenv("DROPBOX_TEST_ACCOUNT"); - // Print each directory visited. - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) { - System.out.format("Directory : %s%n", dir); - return CONTINUE; - } + URI uri = URI.create("dropbox:///?id=" + email); + FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); - // If there is some error accessing - // the file, let the user know. - // If you don't override this method - // and an error occurs, an IOException - // is thrown. - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) { - System.err.println(exc); - return CONTINUE; - } + testMoveFolder(fs); } } From bfd0395fe6e286126d9062a60056402b15f93c7a Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 27 Feb 2024 19:56:09 +0900 Subject: [PATCH 11/13] update settings --- .github/workflows/codeql-analysis.yml | 12 ++++++++---- .github/workflows/maven.yml | 4 ++-- README.md | 1 + pom.xml | 8 +------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d6abfec..8874a36 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,10 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write strategy: fail-fast: false @@ -30,11 +34,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -45,7 +49,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' @@ -65,4 +69,4 @@ jobs: run: mvn -B package --file pom.xml -DskipTests - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 808564c..d706f06 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -9,14 +9,14 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Check w/o SNAPSHOT when "bump version" if: ${{ contains(github.event.head_commit.message, 'bump version') }} run: grep "" pom.xml | head -1 | grep -v SNAPSHOT - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' diff --git a/README.md b/README.md index 56126e1..5059e87 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,4 @@ https://github.com/umjammer/vavi-apps-fuse/blob/master/vavi-nio-file-gathered/sr ## TODO * ~~project name to vavi-nio-file-dropbox~~ + * rename main branch diff --git a/pom.xml b/pom.xml index 16e05bb..3a4635a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ vavi-nio-file-dropbox 0.0.20v - java7-fs-dropbox + vavi-nio-file-dropbox A Java 7 FileSystem implementation over DropBox https://github.com/umjammer/vavi-nio-file-dropbox @@ -152,12 +152,6 @@ 0.1.9 - - org.eclipse.jetty.websocket - javax-websocket-client-impl - 9.4.53.v20231009 - - org.junit.jupiter junit-jupiter-api From c4efc5291eb53175ad9fb3698518054ad8269595 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 27 Feb 2024 19:56:42 +0900 Subject: [PATCH 12/13] bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3a4635a..5ba76a0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.fge vavi-nio-file-dropbox - 0.0.20v + 0.0.21 vavi-nio-file-dropbox A Java 7 FileSystem implementation over DropBox From f3255b706ce1bb8ad6650f5d30ece9aa1f15fb15 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 27 Feb 2024 19:58:02 +0900 Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=A5=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codeql-analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8874a36..ec49d5b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -7,10 +7,10 @@ name: "CodeQL" on: push: - branches: [api-v2-compliant] + branches: [main] pull_request: # The branches below must be a subset of the branches above - branches: [api-v2-compliant] + branches: [main] # schedule: # - cron: '0 2 * * 6'