@Test public void testSEQWARE1410() throws IOException { try { File sudoersFile = new File("/etc/sudoers"); if (!sudoersFile.exists()) { Log.fatal("Could not test FileTools on file where we have no read rights"); } ArrayList<File> files = new ArrayList<>(); FileTools.listFilesRecursive(sudoersFile, files); } catch (Exception e) { Assert.assertTrue("Did not avoid crash when listing file with no read permissions", false); } }
public static void listFilesRecursive(File path, List<File> filesArray) { if (path.exists()) { File[] files = path.listFiles(); if (files == null) { Log.fatal("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); Log.stderr("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); } for (int i = 0; files != null && i < files.length; i++) { if (files[i].isDirectory()) { FileTools.listFilesRecursive(files[i], filesArray); } filesArray.add(files[i]); } } }
FileTools { public static void listFilesRecursive(File path, List<File> filesArray) { if (path.exists()) { File[] files = path.listFiles(); if (files == null) { Log.fatal("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); Log.stderr("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); } for (int i = 0; files != null && i < files.length; i++) { if (files[i].isDirectory()) { FileTools.listFilesRecursive(files[i], filesArray); } filesArray.add(files[i]); } } } }
FileTools { public static void listFilesRecursive(File path, List<File> filesArray) { if (path.exists()) { File[] files = path.listFiles(); if (files == null) { Log.fatal("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); Log.stderr("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); } for (int i = 0; files != null && i < files.length; i++) { if (files[i].isDirectory()) { FileTools.listFilesRecursive(files[i], filesArray); } filesArray.add(files[i]); } } }  }
FileTools { public static void listFilesRecursive(File path, List<File> filesArray) { if (path.exists()) { File[] files = path.listFiles(); if (files == null) { Log.fatal("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); Log.stderr("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); } for (int i = 0; files != null && i < files.length; i++) { if (files[i].isDirectory()) { FileTools.listFilesRecursive(files[i], filesArray); } filesArray.add(files[i]); } } }  static String byte2HexString(byte[] b); static ReturnValue verifyFile(File file); static ReturnValue dirPathExistsAndWritable(File file); static ReturnValue dirPathExistsAndReadable(File file); static ReturnValue fileExistsAndReadable(File file); static ReturnValue fileExistsAndNotEmpty(File file); static File createTempDirectory(File parentDir); static File createDirectoryWithUniqueName(File parentDir, String prefix); static File createFileWithUniqueName(File parentDir, String prefix); static boolean deleteDirectoryRecursive(File path); static boolean zipDirectoryRecursive(File path, File zipFileName, boolean compress); static boolean unzipFile(File path, File outputDir); static void listFilesRecursive(File path, List<File> filesArray); static Map<String, String> getKeyValueFromFile(String path); static boolean isFileOwner(String path); static String whoAmI(); static String getFilename(String filePath); static String getFilePath(String filePath); static LocalhostPair getLocalhost(OptionSet options); }
FileTools { public static void listFilesRecursive(File path, List<File> filesArray) { if (path.exists()) { File[] files = path.listFiles(); if (files == null) { Log.fatal("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); Log.stderr("Could not list file " + path.toString() + " you may not have read permissions, skipping it"); } for (int i = 0; files != null && i < files.length; i++) { if (files[i].isDirectory()) { FileTools.listFilesRecursive(files[i], filesArray); } filesArray.add(files[i]); } } }  static String byte2HexString(byte[] b); static ReturnValue verifyFile(File file); static ReturnValue dirPathExistsAndWritable(File file); static ReturnValue dirPathExistsAndReadable(File file); static ReturnValue fileExistsAndReadable(File file); static ReturnValue fileExistsAndNotEmpty(File file); static File createTempDirectory(File parentDir); static File createDirectoryWithUniqueName(File parentDir, String prefix); static File createFileWithUniqueName(File parentDir, String prefix); static boolean deleteDirectoryRecursive(File path); static boolean zipDirectoryRecursive(File path, File zipFileName, boolean compress); static boolean unzipFile(File path, File outputDir); static void listFilesRecursive(File path, List<File> filesArray); static Map<String, String> getKeyValueFromFile(String path); static boolean isFileOwner(String path); static String whoAmI(); static String getFilename(String filePath); static String getFilePath(String filePath); static LocalhostPair getLocalhost(OptionSet options); static final String FORCE_HOST; }