Java Code Examples for org.apache.commons.io.FileUtils#isSymlink()
The following examples show how to use
org.apache.commons.io.FileUtils#isSymlink() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IrisHalImpl.java From arcusplatform with Apache License 2.0 | 6 votes |
private void createFilelist(File file) { // Is this a file, then add directly if (file.isFile() || (file.isHidden() && !file.isDirectory())) { zipFilelist.add(file.getPath()); return; } // Symlink? try { if (FileUtils.isSymlink(file)) { zipFilelist.add(Files.readSymbolicLink(file.toPath()).toString()); return; } } catch (IOException e) { // Skip on error return; } // If directory, dig down if (file.isDirectory()) { String[] dirContents = file.list(); for (String filename : dirContents) { createFilelist(new File(file, filename)); } } }
Example 2
Source File: InJvmContainerExecutor.java From hadoop-mini-clusters with Apache License 2.0 | 6 votes |
/** * Will clean up symlinks that were created by a launch script */ private void cleanUp() { try { File file = new File(System.getProperty("user.dir")); String[] links = file.list(); for (String name : links) { File potentialSymLink = new File(file, name); if (FileUtils.isSymlink(potentialSymLink)) { if (logger.isDebugEnabled()) { logger.debug("DELETING: " + potentialSymLink); } potentialSymLink.delete(); } } } catch (Exception e) { logger.warn("Failed to remove symlinks", e); } }
Example 3
Source File: ReleaseRunnerFileTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Clean a directory, by deleting all files and folders in it. Retain the * top level files or folders, if their names are in the ignores array. * * @param folder * @param ignores * @throws IOException */ private void cleanDirectory(final File folder, final String...ignores) throws IOException { File[] files = folder.listFiles(createIngoreFilter(ignores)); if (files.length > 0) { logInfo("Cleaning folder: "+folder.getAbsolutePath()); for (File file : files) { if (!FileUtils.isSymlink(file)) { // if file is symlink, do not recurse, only delete the link. file.delete(); } else { FileUtils.forceDelete(file); } } } }
Example 4
Source File: FSDownload.java From hadoop with Apache License 2.0 | 4 votes |
/** * Recursively change permissions of all files/dirs on path based * on resource visibility. * Change to 755 or 700 for dirs, 555 or 500 for files. * @param fs FileSystem * @param path Path to modify perms for * @throws IOException * @throws InterruptedException */ private void changePermissions(FileSystem fs, final Path path) throws IOException, InterruptedException { File f = new File(path.toUri()); if (FileUtils.isSymlink(f)) { // avoid following symlinks when changing permissions return; } boolean isDir = f.isDirectory(); FsPermission perm = cachePerms; // set public perms as 755 or 555 based on dir or file if (resource.getVisibility() == LocalResourceVisibility.PUBLIC) { perm = isDir ? PUBLIC_DIR_PERMS : PUBLIC_FILE_PERMS; } // set private perms as 700 or 500 else { // PRIVATE: // APPLICATION: perm = isDir ? PRIVATE_DIR_PERMS : PRIVATE_FILE_PERMS; } LOG.debug("Changing permissions for path " + path + " to perm " + perm); final FsPermission fPerm = perm; if (null == userUgi) { files.setPermission(path, perm); } else { userUgi.doAs(new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { files.setPermission(path, fPerm); return null; } }); } if (isDir) { FileStatus[] statuses = fs.listStatus(path); for (FileStatus status : statuses) { changePermissions(fs, status.getPath()); } } }
Example 5
Source File: FSDownload.java From big-c with Apache License 2.0 | 4 votes |
/** * Recursively change permissions of all files/dirs on path based * on resource visibility. * Change to 755 or 700 for dirs, 555 or 500 for files. * @param fs FileSystem * @param path Path to modify perms for * @throws IOException * @throws InterruptedException */ private void changePermissions(FileSystem fs, final Path path) throws IOException, InterruptedException { File f = new File(path.toUri()); if (FileUtils.isSymlink(f)) { // avoid following symlinks when changing permissions return; } boolean isDir = f.isDirectory(); FsPermission perm = cachePerms; // set public perms as 755 or 555 based on dir or file if (resource.getVisibility() == LocalResourceVisibility.PUBLIC) { perm = isDir ? PUBLIC_DIR_PERMS : PUBLIC_FILE_PERMS; } // set private perms as 700 or 500 else { // PRIVATE: // APPLICATION: perm = isDir ? PRIVATE_DIR_PERMS : PRIVATE_FILE_PERMS; } LOG.debug("Changing permissions for path " + path + " to perm " + perm); final FsPermission fPerm = perm; if (null == userUgi) { files.setPermission(path, perm); } else { userUgi.doAs(new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { files.setPermission(path, fPerm); return null; } }); } if (isDir) { FileStatus[] statuses = fs.listStatus(path); for (FileStatus status : statuses) { changePermissions(fs, status.getPath()); } } }
Example 6
Source File: IsFileSymbolicLink.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void file_is_symbolic_link_apache_commons() throws IOException { boolean isSymbolicLink = FileUtils.isSymlink(source.toFile()); assertFalse(isSymbolicLink); }