Skip to content

Commit

Permalink
0001870: Include directory listing of symmetricds installation in sna…
Browse files Browse the repository at this point in the history
…pshot
  • Loading branch information
chenson42 committed Aug 11, 2014
1 parent 357c476 commit cfaf1e6
Showing 1 changed file with 41 additions and 0 deletions.
Expand Up @@ -264,6 +264,7 @@ public static File createSnapshot(ISymmetricEngine engine) {

writeRuntimeStats(engine, tmpDir);
writeJobsStats(engine, tmpDir);
writeDirectoryListing(engine, tmpDir);

fos = null;
try {
Expand All @@ -289,6 +290,46 @@ public static File createSnapshot(ISymmetricEngine engine) {
}
}

protected static void writeDirectoryListing(ISymmetricEngine engine, File tmpDir) {
try {
File home = new File(System.getProperty("user.dir"));
if (home.getName().equalsIgnoreCase("bin")) {
home = home.getParentFile();
}

StringBuilder output = new StringBuilder();
printDirectoryContents(home, output);
FileUtils.write(new File(tmpDir, "directory-listing.txt"), output);
} catch (Exception ex) {
log.warn("Failed to output the direcetory listing" , ex);
}
}

protected static void printDirectoryContents(File dir, StringBuilder output) throws IOException {
output.append("\n");
output.append(dir.getCanonicalPath());
output.append("\n");

File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
printDirectoryContents(file, output);
} else {
output.append(" ");
output.append(file.canRead() ? "r" : "-");
output.append(file.canWrite() ? "w" : "-");
output.append(file.canExecute() ? "x" : "-");
output.append(StringUtils.leftPad(file.length() + "", 11));
output.append(" ");
output.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(file.lastModified())));
output.append(" ");
output.append(file.getName());
output.append("\n");
}
}

}

protected static void writeRuntimeStats(ISymmetricEngine engine, File tmpDir) {
FileOutputStream fos = null;
try {
Expand Down

0 comments on commit cfaf1e6

Please sign in to comment.