change diff format to better suit HQ
This commit is contained in:
parent
16fcee7b8c
commit
4f4cb3643b
|
@ -1,9 +1,14 @@
|
||||||
package net.hyperic.sigar;
|
package net.hyperic.sigar;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class FileInfo extends FileAttrs {
|
public class FileInfo extends FileAttrs {
|
||||||
|
|
||||||
|
private static final SimpleDateFormat DATE_FORMAT =
|
||||||
|
new SimpleDateFormat("MMM dd HH:mm");
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
private Sigar sigar;
|
private Sigar sigar;
|
||||||
private boolean dirStatEnabled = false;
|
private boolean dirStatEnabled = false;
|
||||||
|
@ -168,6 +173,52 @@ public class FileInfo extends FileAttrs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Diff {
|
||||||
|
private String attr, old, cur;
|
||||||
|
|
||||||
|
Diff(String attr, String old, String cur) {
|
||||||
|
this.attr = attr;
|
||||||
|
this.old = old;
|
||||||
|
this.cur = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
Diff(String attr, int old, int cur) {
|
||||||
|
this(attr,
|
||||||
|
String.valueOf(old),
|
||||||
|
String.valueOf(cur));
|
||||||
|
}
|
||||||
|
|
||||||
|
Diff(String attr, long old, long cur) {
|
||||||
|
this(attr,
|
||||||
|
String.valueOf(old),
|
||||||
|
String.valueOf(cur));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.attr + ": " +
|
||||||
|
this.old + "|" + this.cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringBuffer format(ArrayList changes) {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
|
if (changes.size() == 0) {
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = changes.size();
|
||||||
|
for (int i=0; i<size; i++) {
|
||||||
|
sb.append('{').append(changes.get(i)).append('}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatDate(long time) {
|
||||||
|
return DATE_FORMAT.format(new Date(time));
|
||||||
|
}
|
||||||
|
|
||||||
public String diff() {
|
public String diff() {
|
||||||
if (this.oldInfo == null) {
|
if (this.oldInfo == null) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -177,165 +228,123 @@ public class FileInfo extends FileAttrs {
|
||||||
|
|
||||||
public String diff(DirStat stat) {
|
public String diff(DirStat stat) {
|
||||||
DirStat thisStat = this.stat;
|
DirStat thisStat = this.stat;
|
||||||
StringBuffer sb = new StringBuffer();
|
ArrayList changes = new ArrayList();
|
||||||
|
|
||||||
if (thisStat.files != stat.files) {
|
if (thisStat.files != stat.files) {
|
||||||
sb.append("Files........").
|
changes.add(new Diff("Files",
|
||||||
append(stat.files).
|
stat.getFiles(),
|
||||||
append(DIFF_SEP).
|
thisStat.getFiles()));
|
||||||
append(thisStat.files).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thisStat.subdirs != stat.subdirs) {
|
if (thisStat.subdirs != stat.subdirs) {
|
||||||
sb.append("Subdirs......").
|
changes.add(new Diff("Subdirs",
|
||||||
append(stat.subdirs).
|
stat.getSubdirs(),
|
||||||
append(DIFF_SEP).
|
thisStat.getSubdirs()));
|
||||||
append(thisStat.subdirs).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thisStat.symlinks != stat.symlinks) {
|
if (thisStat.symlinks != stat.symlinks) {
|
||||||
sb.append("Symlinks.....").
|
changes.add(new Diff("Symlinks",
|
||||||
append(stat.symlinks).
|
stat.getSymlinks(),
|
||||||
append(DIFF_SEP).
|
thisStat.getSymlinks()));
|
||||||
append(thisStat.symlinks).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thisStat.chrdevs != stat.chrdevs) {
|
if (thisStat.chrdevs != stat.chrdevs) {
|
||||||
sb.append("Chrdevs......").
|
changes.add(new Diff("Chrdevs",
|
||||||
append(stat.chrdevs).
|
stat.getChrdevs(),
|
||||||
append(DIFF_SEP).
|
thisStat.getChrdevs()));
|
||||||
append(thisStat.chrdevs).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thisStat.blkdevs != stat.blkdevs) {
|
if (thisStat.blkdevs != stat.blkdevs) {
|
||||||
sb.append("Blkdevs......").
|
changes.add(new Diff("Blkdevs",
|
||||||
append(stat.blkdevs).
|
stat.getBlkdevs(),
|
||||||
append(DIFF_SEP).
|
thisStat.getBlkdevs()));
|
||||||
append(thisStat.blkdevs).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thisStat.sockets != stat.sockets) {
|
if (thisStat.sockets != stat.sockets) {
|
||||||
sb.append("Sockets......").
|
changes.add(new Diff("Sockets",
|
||||||
append(stat.sockets).
|
stat.getSockets(),
|
||||||
append(DIFF_SEP).
|
thisStat.getSockets()));
|
||||||
append(thisStat.sockets).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thisStat.total != stat.total) {
|
if (thisStat.total != stat.total) {
|
||||||
sb.append("Total........").
|
changes.add(new Diff("Total",
|
||||||
append(stat.total).
|
stat.getTotal(),
|
||||||
append(DIFF_SEP).
|
thisStat.getTotal()));
|
||||||
append(thisStat.total).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return format(changes).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String diff(FileInfo info) {
|
public String diff(FileInfo info) {
|
||||||
StringBuffer sb = new StringBuffer();
|
ArrayList changes = new ArrayList();
|
||||||
boolean changed = false;
|
|
||||||
|
|
||||||
if (this.ctime != info.ctime) {
|
if (this.getMtime() != info.getMtime()) {
|
||||||
sb.append("Ctime........").
|
changes.add(new Diff("Mtime",
|
||||||
append(new Date(info.ctime)).
|
formatDate(info.getMtime()),
|
||||||
append(DIFF_SEP).
|
formatDate(this.getMtime())));
|
||||||
append(new Date(this.ctime)).
|
|
||||||
append("\n");
|
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
|
else if (this.getCtime() != info.getCtime()) {
|
||||||
if (this.mtime != info.mtime) {
|
changes.add(new Diff("Ctime",
|
||||||
sb.append("Mtime........").
|
formatDate(info.getCtime()),
|
||||||
append(new Date(info.mtime)).
|
formatDate(this.getCtime())));
|
||||||
append(DIFF_SEP).
|
|
||||||
append(new Date(this.mtime)).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
else if (!changed) {
|
else {
|
||||||
//no point in checking the rest if all times are the same.
|
//no point in checking the rest if all times are the same.
|
||||||
//or should we include atime in the diff?
|
//or should we include atime in the diff?
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.atime != info.atime) {
|
if (this.getPermissions() != info.getPermissions()) {
|
||||||
sb.append("Atime........").
|
changes.add(new Diff("Perms",
|
||||||
append(new Date(info.atime)).
|
info.getPermissionsString(),
|
||||||
append(DIFF_SEP).
|
this.getPermissionsString()));
|
||||||
append(new Date(this.atime)).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.permissions != info.permissions) {
|
if (this.getType() != info.getType()) {
|
||||||
sb.append("Permissions..").
|
changes.add(new Diff("Type",
|
||||||
append(getPermissionsString(info.permissions)).
|
info.getTypeString(),
|
||||||
append(DIFF_SEP).
|
this.getTypeString()));
|
||||||
append(getPermissionsString(this.permissions)).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.type != info.type) {
|
if (this.getUid() != info.getUid()) {
|
||||||
sb.append("Type.........").
|
changes.add(new Diff("Uid",
|
||||||
append(getTypeString(info.type)).
|
info.getUid(),
|
||||||
append(DIFF_SEP).
|
this.getUid()));
|
||||||
append(getTypeString(this.type)).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.uid != info.uid) {
|
if (this.getGid() != info.getGid()) {
|
||||||
sb.append("Uid..........").
|
changes.add(new Diff("Gid",
|
||||||
append(info.uid).
|
info.getGid(),
|
||||||
append(DIFF_SEP).
|
this.getGid()));
|
||||||
append(this.uid).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.gid != info.gid) {
|
if (this.getSize() != info.getSize()) {
|
||||||
sb.append("Gid..........").
|
changes.add(new Diff("Size",
|
||||||
append(info.gid).
|
info.getSize(),
|
||||||
append(DIFF_SEP).
|
this.getSize()));
|
||||||
append(this.gid).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.inode != info.inode) {
|
if (!OperatingSystem.IS_WIN32) {
|
||||||
sb.append("Inode........").
|
if (this.getInode() != info.getInode()) {
|
||||||
append(info.inode).
|
changes.add(new Diff("Inode",
|
||||||
append(DIFF_SEP).
|
info.getInode(),
|
||||||
append(this.inode).
|
this.getInode()));
|
||||||
append("\n");
|
}
|
||||||
}
|
|
||||||
|
if (this.getDevice() != info.getDevice()) {
|
||||||
if (this.device != info.device) {
|
changes.add(new Diff("Device",
|
||||||
sb.append("Device.......").
|
info.getDevice(),
|
||||||
append(info.device).
|
this.getDevice()));
|
||||||
append(DIFF_SEP).
|
}
|
||||||
append(this.device).
|
|
||||||
append("\n");
|
if (this.getNlink() != info.getNlink()) {
|
||||||
}
|
changes.add(new Diff("Nlink",
|
||||||
|
info.getNlink(),
|
||||||
if (this.nlink != info.nlink) {
|
this.getNlink()));
|
||||||
sb.append("Nlink........").
|
}
|
||||||
append(info.nlink).
|
|
||||||
append(DIFF_SEP).
|
|
||||||
append(this.nlink).
|
|
||||||
append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.size != info.size) {
|
|
||||||
sb.append("Size.........").
|
|
||||||
append(info.size).
|
|
||||||
append(DIFF_SEP).
|
|
||||||
append(this.size).
|
|
||||||
append("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuffer sb = format(changes);
|
||||||
if (this.dirStatEnabled) {
|
if (this.dirStatEnabled) {
|
||||||
sb.append(diff(info.stat));
|
sb.append(diff(info.stat));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue