"Can't handle single and double quotes in same argument"); if (Utils.isWindows()) { return buf.append(DOUBLE_QUOTE).append(cleanedArgument.replace("\"", "\\\"")).append(DOUBLE_QUOTE).toString(); } else {
/** * @return The FileSystem implementation for the OS */ protected FileSystem getFileSystem() { return Utils.isWindows() ? new WindowsFileSystem(this) : new FileSystemImpl(this); }
private void setPerms(Path path, String perms) { if (Utils.isWindows() == false) { try { Files.setPosixFilePermissions( path, PosixFilePermissions.fromString(perms) ); } catch(IOException e) { throw new RuntimeException(e.getMessage()); } } }
private void assertPerms(String perms, String file1) { if (!Utils.isWindows()) { assertEquals(perms, getPerms(file1)); } }
@Test public void testReadSymLink() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; Files.createSymbolicLink(Paths.get(testDir + pathSep + linkName), Paths.get(fileName)); vertx.fileSystem().readSymlink(testDir + pathSep + linkName, ar -> { if (ar.failed()) { fail(ar.cause().getMessage()); } else { assertEquals(fileName, ar.result()); testComplete(); } }); await(); }
@Test public void testCreateTempFileWithPermsBlocking() throws Exception { Assume.assumeFalse(Utils.isWindows()); FileSystem fs = vertx.fileSystem(); String tempFile = fs.createTempFileBlocking("project", ".tmp", DEFAULT_FILE_PERMS); Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); String perms = PosixFilePermissions.toString(Files.getPosixFilePermissions(path)); assertEquals(perms, DEFAULT_FILE_PERMS); } }
@Test public void testCreateTempDirectoryWithPermsBlocking() throws Exception { Assume.assumeFalse(Utils.isWindows()); FileSystem fs = vertx.fileSystem(); String tempDirectory = fs.createTempDirectoryBlocking("project", DEFAULT_DIR_PERMS); String perms = PosixFilePermissions.toString(Files.getPosixFilePermissions(Paths.get(tempDirectory))); assertEquals(perms, DEFAULT_DIR_PERMS); }
@Test public void testChownToOwnGroup() throws Exception { // Not supported in WindowsFileSystemProvider Assume.assumeFalse(Utils.isWindows()); String file1 = "some-file.dat"; createFileWithJunk(file1, 100); String fullPath = testDir + pathSep + file1; Path path = Paths.get(fullPath); GroupPrincipal group = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).group(); vertx.fileSystem().chown(fullPath, null, group.getName(), ar -> { deleteFile(file1); assertTrue(ar.succeeded()); testComplete(); }); await(); }
@Test public void testPropsDontFollowLink() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; Files.createSymbolicLink(Paths.get(testDir + pathSep + linkName), Paths.get(fileName)); testProps(linkName, true, true, st -> { assertNotNull(st != null); assertTrue(st.isSymbolicLink()); }); await(); }
@Test public void testCreateTempFileWithPerms() { Assume.assumeFalse(Utils.isWindows()); FileSystem fs = vertx.fileSystem(); fs.createTempFile("project", ".tmp", DEFAULT_FILE_PERMS, onSuccess(tempFile -> { Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); try { String perms = PosixFilePermissions.toString(Files.getPosixFilePermissions(path)); assertEquals(perms, DEFAULT_FILE_PERMS); } catch (IOException e) { fail(e); } })); }
@Test public void testAddArgument() throws Exception { List<String> args = new ArrayList<>(); ExecUtils.addArgument(args, "hello"); ExecUtils.addArgument(args, "-foo"); ExecUtils.addArgument(args, "--bar"); ExecUtils.addArgument(args, "--baz=hello"); ExecUtils.addArgument(args, "with spaces"); ExecUtils.addArgument(args, "with'single'_quotes"); ExecUtils.addArgument(args, "with\"double\"quotes"); ExecUtils.addArgument(args, "with \"double\" quotes and spaces"); ExecUtils.addArgument(args, "with 'single' quotes and spaces"); ExecUtils.addArgument(args, "'wrapped_in_single_quotes'"); ExecUtils.addArgument(args, "\"wrapped_in_double_quotes\""); assertThat(args).contains( "hello", "-foo", "--bar", "--baz=hello", "\"with spaces\"", "\"with'single'_quotes\"", Utils.isWindows() ? "\"with\\\"double\\\"quotes\"" : "'with\"double\"quotes'", Utils.isWindows() ? "\"with \\\"double\\\" quotes and spaces\"" : "'with \"double\" quotes and spaces'", "\"with 'single' quotes and spaces\"", "wrapped_in_single_quotes", "wrapped_in_double_quotes"); }
@Test public void testCreateTempDirectoryWithPerms() { Assume.assumeFalse(Utils.isWindows()); FileSystem fs = vertx.fileSystem(); fs.createTempDirectory("project", DEFAULT_DIR_PERMS, onSuccess(tempDirectory -> { try { String perms = PosixFilePermissions.toString(Files.getPosixFilePermissions(Paths.get(tempDirectory))); assertEquals(perms, DEFAULT_DIR_PERMS); } catch (IOException e) { fail(e); } complete(); })); await(); }
@Test public void testSymLink() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String symlinkName = "some-sym-link.txt"; testLink(symlinkName, fileName, true, true, v -> { assertEquals(fileSize, fileLength(symlinkName)); assertTrue(Files.isSymbolicLink(Paths.get(testDir + pathSep + symlinkName))); // Now try reading it String read = vertx.fileSystem().readSymlinkBlocking(testDir + pathSep + symlinkName); assertEquals(fileName, read); }); await(); }
@Test public void testCopyNoFollowLinks() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String source = "foo.txt"; String link = "link.txt"; String target = "bar.txt"; createFileWithJunk(source, 100); try { Files.createSymbolicLink(new File(testDir, link).toPath(), new File(testDir, source).toPath()); } catch (UnsupportedOperationException e) { throw new AssumptionViolatedException("Links unsupported"); } FileSystem fs = vertx.fileSystem(); String from = testDir + pathSep + link; String to = testDir + pathSep + target; CopyOptions options = new CopyOptions().setNofollowLinks(true); fs.copy(from, to, options, onSuccess(v -> { fs.lprops(to, onSuccess(props -> { assertTrue(props.isSymbolicLink()); fs.readFile(from, onSuccess(expected -> { fs.readFile(to, onSuccess(actual -> { assertEquals(expected, actual); complete(); })); })); })); })); await(); }
@Test public void testPropsFollowLink() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String fileName = "some-file.txt"; long fileSize = 1234; // The times are quite inaccurate so we give 1 second leeway long start = 1000 * (System.currentTimeMillis() / 1000 - 1); createFileWithJunk(fileName, fileSize); long end = 1000 * (System.currentTimeMillis() / 1000 + 1); String linkName = "some-link.txt"; Files.createSymbolicLink(Paths.get(testDir + pathSep + linkName), Paths.get(fileName)); testProps(linkName, false, true, st -> { assertNotNull(st); assertEquals(fileSize, st.size()); assertTrue(st.creationTime() >= start); assertTrue(st.creationTime() <= end); assertTrue(st.lastAccessTime() >= start); assertTrue(st.lastAccessTime() <= end); assertTrue(st.lastModifiedTime() >= start); assertTrue(st.lastModifiedTime() <= end); assertFalse(st.isDirectory()); assertFalse(st.isOther()); assertTrue(st.isRegularFile()); assertFalse(st.isSymbolicLink()); }); await(); }
"Can't handle single and double quotes in same argument"); if (Utils.isWindows()) { return buf.append(DOUBLE_QUOTE).append(cleanedArgument.replace("\"", "\\\"")).append(DOUBLE_QUOTE).toString(); } else {
/** * @return The FileSystem implementation for the OS */ protected FileSystem getFileSystem() { return Utils.isWindows() ? new WindowsFileSystem(this) : new FileSystemImpl(this); }
private void setPerms(Path path, String perms) { if (Utils.isWindows() == false) { try { Files.setPosixFilePermissions( path, PosixFilePermissions.fromString(perms) ); } catch(IOException e) { throw new RuntimeException(e.getMessage()); } } }
private void assertPerms(String perms, String file1) { if (!Utils.isWindows()) { assertEquals(perms, getPerms(file1)); } }
@Test public void testReadSymLink() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; Files.createSymbolicLink(Paths.get(testDir + pathSep + linkName), Paths.get(fileName)); vertx.fileSystem().readSymlink(testDir + pathSep + linkName, ar -> { if (ar.failed()) { fail(ar.cause().getMessage()); } else { assertEquals(fileName, ar.result()); testComplete(); } }); await(); }