void createLink(Path link, Path existing) throws IOException { Files.createLink(link, existing); }
/** * Creates a hardlink * @param file - existing source file * @param linkName - desired target link file */ public static void createHardLink(File file, File linkName) throws IOException { if (file == null) { throw new IOException( "invalid arguments to createHardLink: source file is null"); } if (linkName == null) { throw new IOException( "invalid arguments to createHardLink: link name is null"); } createLink(linkName.toPath(), file.toPath()); }
createLink(linkDir.toPath().resolve(name), parentDir.toPath().resolve(name));
/** * This recreates the new working directory of the recovered RocksDB instance and links/copies the contents from * a local state. */ private void restoreInstanceDirectoryFromPath(Path source) throws IOException { FileSystem fileSystem = source.getFileSystem(); final FileStatus[] fileStatuses = fileSystem.listStatus(source); if (fileStatuses == null) { throw new IOException("Cannot list file statues. Directory " + source + " does not exist."); } for (FileStatus fileStatus : fileStatuses) { final Path filePath = fileStatus.getPath(); final String fileName = filePath.getName(); File restoreFile = new File(source.getPath(), fileName); File targetFile = new File(stateBackend.instanceRocksDBPath.getPath(), fileName); if (fileName.endsWith(SST_FILE_SUFFIX)) { // hardlink'ing the immutable sst-files. Files.createLink(targetFile.toPath(), restoreFile.toPath()); } else { // true copy for all other files. Files.copy(restoreFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } } }
public Void perform() { try { Path source = vertx.resolveFile(link).toPath(); Path target = vertx.resolveFile(existing).toPath(); if (symbolic) { Files.createSymbolicLink(source, target); } else { Files.createLink(source, target); } } catch (IOException e) { throw new FileSystemException(e); } return null; } };
Files.createLink(linkFile.toPath(), Paths.get(targetFile.getAbsolutePath())); linkCount++;
Files.createLink(path, tempPath); } catch (FileAlreadyExistsException e) { try {
public void testEqual_links() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path fooPath = fs.getPath("foo"); MoreFiles.asCharSink(fooPath, UTF_8).write("foo"); Path fooSymlink = fs.getPath("symlink"); Files.createSymbolicLink(fooSymlink, fooPath); Path fooHardlink = fs.getPath("hardlink"); Files.createLink(fooHardlink, fooPath); assertThat(MoreFiles.equal(fooPath, fooSymlink)).isTrue(); assertThat(MoreFiles.equal(fooPath, fooHardlink)).isTrue(); assertThat(MoreFiles.equal(fooSymlink, fooHardlink)).isTrue(); } }
Files.createLink(path, tempPath); } catch (FileAlreadyExistsException e) { try {
@Test public void testUnlink() throws Exception { String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; Files.createLink(Paths.get(testDir + pathSep + linkName), Paths.get(testDir + pathSep + fileName)); assertEquals(fileSize, fileLength(linkName)); vertx.fileSystem().unlink(testDir + pathSep + linkName, createHandler(true, v -> assertFalse(fileExists(linkName)))); await(); }
"snap_v2_" + DateUtil.formatInstant(DateUtil.yyyyMMddHHmm, now)); snapshotDir.toFile().mkdirs(); Files.createLink(Paths.get(snapshotDir.toString(), file2.getFileName().toString()), file2); Files.createLink(Paths.get(snapshotDir.toString(), file3.getFileName().toString()), file3); Files.createLink(Paths.get(snapshotDir.toString(), file4.getFileName().toString()), file4);
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.getFileName().toString(); if (Files.isRegularFile(file) && name.startsWith(NNStorage.NameNodeFile.EDITS.getName())) { Path newFile = curDir.resolve(name); Files.createLink(newFile, file); } return super.visitFile(file, attrs); } }
Path link = null; try { link = Files.createLink( Paths.get(lock.getAbsolutePath() + ".lnk"), //$NON-NLS-1$ lockPath);
public Void perform() { try { Path source = vertx.resolveFile(link).toPath(); Path target = vertx.resolveFile(existing).toPath(); if (symbolic) { Files.createSymbolicLink(source, target); } else { Files.createLink(source, target); } } catch (IOException e) { throw new FileSystemException(e); } return null; } };
Path path = file.toPath(); try { link = Files.createLink(Paths.get(uniqueLinkPath(file)), path); Integer nlink = (Integer) (Files.getAttribute(path, "unix:nlink")); //$NON-NLS-1$
@Test public void testUnlink() throws Exception { String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; Files.createLink(Paths.get(testDir + pathSep + linkName), Paths.get(testDir + pathSep + fileName)); assertEquals(fileSize, fileLength(linkName)); vertx.fileSystem().unlink(testDir + pathSep + linkName, createHandler(true, v -> assertFalse(fileExists(linkName)))); await(); }
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { super.visitFile(file, attrs); Files.createLink(dest.resolve(src.relativize(file)), file); return FileVisitResult.CONTINUE; } });
@Test @Category( { SlowTest.class, HardLink.class, Writable.class } ) public void testHardLinkModifyOneModifiedDateOfOtherChanged() throws IOException, InterruptedException { Files.createLink( link(), orig() ); FileTime before = Files.getLastModifiedTime( orig() ); waitForAttribute(); Files.write( link(), CONTENT_OTHER ); assertThat( Files.getLastModifiedTime( orig() ) ).isGreaterThan( before ); }
@Test @Category( { HardLink.class, Writable.class, WorkingDirectoryInPlaygroundTree.class} ) public void testHardLinkToRelative() throws IOException { Files.createLink( link(), relativize( orig() ) ); assertThat( Files.isSameFile( link(), orig() ) ).isEqualTo( true ); }
@Test @Category( { SymLink.class, HardLink.class, Delete.class, Writable.class } ) public void testHardLinkToSymLinkDeleteSymLeavesHardLinkUntouched() throws IOException { Files.createSymbolicLink( symLink(), targetFile() ); Files.createLink( hardLink(), symLink() ); Files.delete( symLink() ); //assertThat( hardLink() ).hasBinaryContent( CONTENT ); assertThat( Files.readAllBytes( hardLink() ) ).isEqualTo( CONTENT ); }