@SuppressWarnings("deprecation") @Override public void createSymlink(Path target, Path link, boolean createParent) throws IOException { if (!FileSystem.areSymlinksEnabled()) { throw new UnsupportedOperationException("Symlinks not supported"); } final String targetScheme = target.toUri().getScheme(); if (targetScheme != null && !"file".equals(targetScheme)) { throw new IOException("Unable to create symlink to non-local file "+ "system: "+target.toString()); } if (createParent) { mkdirs(link.getParent()); } // NB: Use createSymbolicLink in java.nio.file.Path once available int result = FileUtil.symLink(target.toString(), makeAbsolute(link).toString()); if (result != 0) { throw new IOException("Error " + result + " creating symlink " + link + " to " + target); } }
String target = p.toUri().getPath(); String link = workDir + Path.SEPARATOR + p.getName(); if (FileUtil.symLink(target, link) != 0) { throw new IOException("Cannot link to added file: " + target + " from: " + link);
String target = p.toUri().getPath(); String link = workDir + Path.SEPARATOR + p.getName(); if (FileUtil.symLink(target, link) != 0) { throw new IOException("Cannot link to added file: " + target + " from: " + link);
String target = p.toUri().getPath(); String link = workDir + Path.SEPARATOR + p.getName(); if (FileUtil.symLink(target, link) != 0) { throw new IOException ("Cannot link to added file: " + target + " from: " + link);
String target = p.toUri().getPath(); String link = workDir + Path.SEPARATOR + p.getName(); if (FileUtil.symLink(target, link) != 0) { throw new IOException ("Cannot link to added file: " + target + " from: " + link);
@Override public void symLink(String target, String symlink) throws IOException { FileUtil.symLink(target, symlink); }
/** * Utility method for creating a symlink and warning on errors. * * If link is null, does nothing. */ private static void symlink(File workDir, String target, String link) throws IOException { if (link != null) { link = workDir.toString() + Path.SEPARATOR + link; File flink = new File(link); if (!flink.exists()) { LOG.info(String.format("Creating symlink: %s <- %s", target, link)); if (0 != FileUtil.symLink(target, link)) { LOG.warn(String.format("Failed to create symlink: %s <- %s", target, link)); } } } }
/** * Creates 1 subdirectory and 1 file under dir2. Creates 1 subdir, 1 file, * 1 symlink to a dir and a symlink to a file under dir1. * Creates dir1/subDir, dir1/file, dir2/subDir, dir2/file, * dir1/symlinkSubDir->dir2/subDir, dir1/symlinkFile->dir2/file. */ static void createSubDirsAndSymLinks(JobConf jobConf, Path dir1, Path dir2) throws IOException { FileSystem fs = FileSystem.getLocal(jobConf); createSubDirAndFile(fs, dir1); createSubDirAndFile(fs, dir2); // now create symlinks under dir1 that point to file/dir under dir2 FileUtil.symLink(dir2+"/subDir", dir1+"/symlinkSubDir"); FileUtil.symLink(dir2+"/file", dir1+"/symlinkFile"); }
/** * Utility method for creating a symlink and warning on errors. * * If link is null, does nothing. */ private void symlink(File workDir, String target, String link) throws IOException { if (link != null) { link = workDir.toString() + Path.SEPARATOR + link; File flink = new File(link); if (!flink.exists()) { LOG.info(String.format("Creating symlink: %s <- %s", target, link)); if (0 != FileUtil.symLink(target, link)) { LOG.warn(String.format("Failed to create symlink: %s <- %s", target, link)); } else { symlinksCreated.add(new File(link)); } } } }
/** * Utility method for creating a symlink and warning on errors. * * If link is null, does nothing. */ private void symlink(File workDir, String target, String link) throws IOException { if (link != null) { link = workDir.toString() + Path.SEPARATOR + link; File flink = new File(link); if (!flink.exists()) { LOG.info(String.format("Creating symlink: %s <- %s", target, link)); if (0 != FileUtil.symLink(target, link)) { LOG.warn(String.format("Failed to create symlink: %s <- %s", target, link)); } else { symlinksCreated.add(new File(link)); } } } }
private static void createSymlink(Configuration conf, URI cache, CacheStatus cacheStatus, boolean isArchive, Path currentWorkDir, boolean honorSymLinkConf) throws IOException { boolean doSymlink = honorSymLinkConf && DistributedCache.getSymlink(conf); if(cache.getFragment() == null) { doSymlink = false; } String link = currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment(); File flink = new File(link); if (doSymlink){ if (!flink.exists()) { FileUtil.symLink(cacheStatus.localizedLoadPath.toString(), link); } } }
private void createSymlink(Configuration conf, URI cache, CacheStatus cacheStatus, boolean isArchive, Path currentWorkDir, boolean honorSymLinkConf) throws IOException { boolean doSymlink = honorSymLinkConf && DistributedCache.getSymlink(conf); if(cache.getFragment() == null) { doSymlink = false; } String link = currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment(); File flink = new File(link); if (doSymlink){ if (!flink.exists()) { FileUtil.symLink(cacheStatus.localizedLoadPath.toString(), link); } } }
/** * Utility method for creating a symlink and warning on errors. * * If link is null, does nothing. */ private void symlink(File workDir, String target, String link) throws IOException { if (link != null) { link = workDir.toString() + Path.SEPARATOR + link; File flink = new File(link); if (!flink.exists()) { LOG.info(String.format("Creating symlink: %s <- %s", target, link)); if (0 != FileUtil.symLink(target, link)) { LOG.warn(String.format("Failed to create symlink: %s <- %s", target, link)); } else { symlinksCreated.add(new File(link)); } } } }
/** * This method create symlinks for all files in a given dir in another directory * @param conf the configuration * @param jobCacheDir the target directory for creating symlinks * @param workDir the directory in which the symlinks are created * @throws IOException */ public static void createAllSymlink(Configuration conf, File jobCacheDir, File workDir) throws IOException{ if ((jobCacheDir == null || !jobCacheDir.isDirectory()) || workDir == null || (!workDir.isDirectory())) { return; } boolean createSymlink = getSymlink(conf); if (createSymlink){ File[] list = jobCacheDir.listFiles(); for (int i=0; i < list.length; i++){ FileUtil.symLink(list[i].getAbsolutePath(), new File(workDir, list[i].getName()).toString()); } } }
@SuppressWarnings("deprecation") @Override public void createSymlink(Path target, Path link, boolean createParent) throws IOException { if (!FileSystem.areSymlinksEnabled()) { throw new UnsupportedOperationException("Symlinks not supported"); } final String targetScheme = target.toUri().getScheme(); if (targetScheme != null && !"file".equals(targetScheme)) { throw new IOException("Unable to create symlink to non-local file "+ "system: "+target.toString()); } if (createParent) { mkdirs(link.getParent()); } // NB: Use createSymbolicLink in java.nio.file.Path once available int result = FileUtil.symLink(target.toString(), makeAbsolute(link).toString()); if (result != 0) { throw new IOException("Error " + result + " creating symlink " + link + " to " + target); } }
@SuppressWarnings("deprecation") @Override public void createSymlink(Path target, Path link, boolean createParent) throws IOException { if (!FileSystem.areSymlinksEnabled()) { throw new UnsupportedOperationException("Symlinks not supported"); } final String targetScheme = target.toUri().getScheme(); if (targetScheme != null && !"file".equals(targetScheme)) { throw new IOException("Unable to create symlink to non-local file "+ "system: "+target.toString()); } if (createParent) { mkdirs(link.getParent()); } // NB: Use createSymbolicLink in java.nio.file.Path once available int result = FileUtil.symLink(target.toString(), makeAbsolute(link).toString()); if (result != 0) { throw new IOException("Error " + result + " creating symlink " + link + " to " + target); } }
@SuppressWarnings("deprecation") @Override public void createSymlink(Path target, Path link, boolean createParent) throws IOException { if (!FileSystem.areSymlinksEnabled()) { throw new UnsupportedOperationException("Symlinks not supported"); } final String targetScheme = target.toUri().getScheme(); if (targetScheme != null && !"file".equals(targetScheme)) { throw new IOException("Unable to create symlink to non-local file "+ "system: "+target.toString()); } if (createParent) { mkdirs(link.getParent()); } // NB: Use createSymbolicLink in java.nio.file.Path once available int result = FileUtil.symLink(target.toString(), makeAbsolute(link).toString()); if (result != 0) { throw new IOException("Error " + result + " creating symlink " + link + " to " + target); } }
@SuppressWarnings("deprecation") @Override public void createSymlink(Path target, Path link, boolean createParent) throws IOException { if (!FileSystem.areSymlinksEnabled()) { throw new UnsupportedOperationException("Symlinks not supported"); } final String targetScheme = target.toUri().getScheme(); if (targetScheme != null && !"file".equals(targetScheme)) { throw new IOException("Unable to create symlink to non-local file "+ "system: "+target.toString()); } if (createParent) { mkdirs(link.getParent()); } // NB: Use createSymbolicLink in java.nio.file.Path once available int result = FileUtil.symLink(target.toString(), makeAbsolute(link).toString()); if (result != 0) { throw new IOException("Error " + result + " creating symlink " + link + " to " + target); } }
/** * Test that deletion of a symlink works as expected. */ @Test (timeout = 30000) public void testSymlinkDelete() throws Exception { Assert.assertFalse(del.exists()); del.mkdirs(); File file = new File(del, FILE); file.createNewFile(); File link = new File(del, "_link"); // create the symlink FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath()); Assert.assertTrue(file.exists()); Assert.assertTrue(link.exists()); // make sure that deleting a symlink works properly Assert.assertTrue(link.delete()); Assert.assertFalse(link.exists()); Assert.assertTrue(file.exists()); }
/** * Test that deletion of a symlink works as expected. */ @Test (timeout = 30000) public void testSymlinkDelete() throws Exception { Assert.assertFalse(del.exists()); del.mkdirs(); File file = new File(del, FILE); file.createNewFile(); File link = new File(del, "_link"); // create the symlink FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath()); Assert.assertTrue(file.exists()); Assert.assertTrue(link.exists()); // make sure that deleting a symlink works properly Assert.assertTrue(link.delete()); Assert.assertFalse(link.exists()); Assert.assertTrue(file.exists()); }