[SIGAR-248]- Sigar log monitoring ignores successive lines with same timestamp
This commit is contained in:
parent
6ed8f3c9b5
commit
47f01e0177
|
@ -295,71 +295,55 @@ public class FileInfo extends FileAttrs implements java.io.Serializable {
|
||||||
ArrayList changes = new ArrayList();
|
ArrayList changes = new ArrayList();
|
||||||
|
|
||||||
if (this.getMtime() != info.getMtime()) {
|
if (this.getMtime() != info.getMtime()) {
|
||||||
changes.add(new Diff("Mtime",
|
changes.add(new Diff("Mtime", formatDate(info.getMtime()),
|
||||||
formatDate(info.getMtime()),
|
|
||||||
formatDate(this.getMtime())));
|
formatDate(this.getMtime())));
|
||||||
}
|
} else if (this.getCtime() != info.getCtime()) {
|
||||||
else if (this.getCtime() != info.getCtime()) {
|
changes.add(new Diff("Ctime", formatDate(info.getCtime()),
|
||||||
changes.add(new Diff("Ctime",
|
|
||||||
formatDate(info.getCtime()),
|
|
||||||
formatDate(this.getCtime())));
|
formatDate(this.getCtime())));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
//no point in checking the rest if all times are the same.
|
|
||||||
//or should we include atime in the diff?
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getPermissions() != info.getPermissions()) {
|
if (this.getPermissions() != info.getPermissions()) {
|
||||||
changes.add(new Diff("Perms",
|
changes.add(new Diff("Perms", info.getPermissionsString(), this
|
||||||
info.getPermissionsString(),
|
.getPermissionsString()));
|
||||||
this.getPermissionsString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getType() != info.getType()) {
|
if (this.getType() != info.getType()) {
|
||||||
changes.add(new Diff("Type",
|
changes.add(new Diff("Type", info.getTypeString(), this
|
||||||
info.getTypeString(),
|
.getTypeString()));
|
||||||
this.getTypeString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getUid() != info.getUid()) {
|
if (this.getUid() != info.getUid()) {
|
||||||
changes.add(new Diff("Uid",
|
changes.add(new Diff("Uid", info.getUid(), this.getUid()));
|
||||||
info.getUid(),
|
|
||||||
this.getUid()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getGid() != info.getGid()) {
|
if (this.getGid() != info.getGid()) {
|
||||||
changes.add(new Diff("Gid",
|
changes.add(new Diff("Gid", info.getGid(), this.getGid()));
|
||||||
info.getGid(),
|
|
||||||
this.getGid()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getSize() != info.getSize()) {
|
if (this.getSize() != info.getSize()) {
|
||||||
changes.add(new Diff("Size",
|
changes.add(new Diff("Size", info.getSize(), this.getSize()));
|
||||||
info.getSize(),
|
|
||||||
this.getSize()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OperatingSystem.IS_WIN32) {
|
if (!OperatingSystem.IS_WIN32) {
|
||||||
if (this.getInode() != info.getInode()) {
|
if (this.getInode() != info.getInode()) {
|
||||||
changes.add(new Diff("Inode",
|
changes.add(new Diff("Inode", info.getInode(), this.getInode()));
|
||||||
info.getInode(),
|
|
||||||
this.getInode()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getDevice() != info.getDevice()) {
|
if (this.getDevice() != info.getDevice()) {
|
||||||
changes.add(new Diff("Device",
|
changes.add(new Diff("Device", info.getDevice(), this
|
||||||
info.getDevice(),
|
.getDevice()));
|
||||||
this.getDevice()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getNlink() != info.getNlink()) {
|
if (this.getNlink() != info.getNlink()) {
|
||||||
changes.add(new Diff("Nlink",
|
changes.add(new Diff("Nlink", info.getNlink(), this.getNlink()));
|
||||||
info.getNlink(),
|
|
||||||
this.getNlink()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if changes were not detected then return empty String */
|
||||||
|
if (changes.isEmpty()){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
StringBuffer sb = format(changes);
|
StringBuffer sb = format(changes);
|
||||||
if (this.dirStatEnabled) {
|
if (this.dirStatEnabled) {
|
||||||
sb.append(diff(info.stat));
|
sb.append(diff(info.stat));
|
||||||
|
@ -389,7 +373,9 @@ public class FileInfo extends FileAttrs implements java.io.Serializable {
|
||||||
|
|
||||||
stat();
|
stat();
|
||||||
|
|
||||||
return this.mtime != oldInfo.mtime;
|
boolean isModified = isModified(this.oldInfo);
|
||||||
|
|
||||||
|
return isModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean changed()
|
public boolean changed()
|
||||||
|
@ -455,4 +441,49 @@ public class FileInfo extends FileAttrs implements java.io.Serializable {
|
||||||
|
|
||||||
return fetchInfo(sigar, name, false);
|
return fetchInfo(sigar, name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isModified(FileInfo info){
|
||||||
|
/* Check modified time */
|
||||||
|
if (this.getMtime() != info.getMtime()) {
|
||||||
|
return true;
|
||||||
|
} else if (this.getCtime() != info.getCtime()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getPermissions() != info.getPermissions()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getType() != info.getType()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getUid() != info.getUid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getGid() != info.getGid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getSize() != info.getSize()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!OperatingSystem.IS_WIN32) {
|
||||||
|
if (this.getInode() != info.getInode()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getDevice() != info.getDevice()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getNlink() != info.getNlink()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,11 +133,11 @@ public class TestFileInfo extends SigarTestCase {
|
||||||
tmp.deleteOnExit();
|
tmp.deleteOnExit();
|
||||||
traceln("TMP=" + file);
|
traceln("TMP=" + file);
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
//stat() mtime is in seconds, this happens to quick to detect change.
|
//stat() mtime is in seconds, this happens to quick to detect change.
|
||||||
Thread.sleep(1000 * 1);
|
//Thread.sleep(1000 * 1);
|
||||||
} catch (InterruptedException e) {
|
// } catch (InterruptedException e) {
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileInfo info = sigar.getFileInfo(file);
|
FileInfo info = sigar.getFileInfo(file);
|
||||||
|
|
Loading…
Reference in New Issue