Skip to content

Commit

Permalink
[SIGAR-248]- Sigar log monitoring ignores successive lines with same …
Browse files Browse the repository at this point in the history
…timestamp
  • Loading branch information
tgoldman committed Sep 30, 2013
1 parent 6ed8f3c commit 47f01e0
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 71 deletions.
165 changes: 98 additions & 67 deletions bindings/java/src/org/hyperic/sigar/FileInfo.java
Expand Up @@ -292,74 +292,58 @@ public String diff(DirStat stat) {
}

public String diff(FileInfo info) {
ArrayList changes = new ArrayList();

if (this.getMtime() != info.getMtime()) {
changes.add(new Diff("Mtime",
formatDate(info.getMtime()),
formatDate(this.getMtime())));
}
else if (this.getCtime() != info.getCtime()) {
changes.add(new Diff("Ctime",
formatDate(info.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?
ArrayList changes = new ArrayList();

if (this.getMtime() != info.getMtime()) {
changes.add(new Diff("Mtime", formatDate(info.getMtime()),
formatDate(this.getMtime())));
} else if (this.getCtime() != info.getCtime()) {
changes.add(new Diff("Ctime", formatDate(info.getCtime()),
formatDate(this.getCtime())));
}

if (this.getPermissions() != info.getPermissions()) {
changes.add(new Diff("Perms", info.getPermissionsString(), this
.getPermissionsString()));
}

if (this.getType() != info.getType()) {
changes.add(new Diff("Type", info.getTypeString(), this
.getTypeString()));
}

if (this.getUid() != info.getUid()) {
changes.add(new Diff("Uid", info.getUid(), this.getUid()));
}

if (this.getGid() != info.getGid()) {
changes.add(new Diff("Gid", info.getGid(), this.getGid()));
}

if (this.getSize() != info.getSize()) {
changes.add(new Diff("Size", info.getSize(), this.getSize()));
}

if (!OperatingSystem.IS_WIN32) {
if (this.getInode() != info.getInode()) {
changes.add(new Diff("Inode", info.getInode(), this.getInode()));
}

if (this.getDevice() != info.getDevice()) {
changes.add(new Diff("Device", info.getDevice(), this
.getDevice()));
}

if (this.getNlink() != info.getNlink()) {
changes.add(new Diff("Nlink", info.getNlink(), this.getNlink()));
}
}

/* if changes were not detected then return empty String */
if (changes.isEmpty()){
return "";
}

if (this.getPermissions() != info.getPermissions()) {
changes.add(new Diff("Perms",
info.getPermissionsString(),
this.getPermissionsString()));
}

if (this.getType() != info.getType()) {
changes.add(new Diff("Type",
info.getTypeString(),
this.getTypeString()));
}

if (this.getUid() != info.getUid()) {
changes.add(new Diff("Uid",
info.getUid(),
this.getUid()));
}

if (this.getGid() != info.getGid()) {
changes.add(new Diff("Gid",
info.getGid(),
this.getGid()));
}

if (this.getSize() != info.getSize()) {
changes.add(new Diff("Size",
info.getSize(),
this.getSize()));
}

if (!OperatingSystem.IS_WIN32) {
if (this.getInode() != info.getInode()) {
changes.add(new Diff("Inode",
info.getInode(),
this.getInode()));
}

if (this.getDevice() != info.getDevice()) {
changes.add(new Diff("Device",
info.getDevice(),
this.getDevice()));
}

if (this.getNlink() != info.getNlink()) {
changes.add(new Diff("Nlink",
info.getNlink(),
this.getNlink()));
}
}


StringBuffer sb = format(changes);
if (this.dirStatEnabled) {
sb.append(diff(info.stat));
Expand Down Expand Up @@ -389,7 +373,9 @@ public boolean modified()

stat();

return this.mtime != oldInfo.mtime;
boolean isModified = isModified(this.oldInfo);

return isModified;
}

public boolean changed()
Expand Down Expand Up @@ -455,4 +441,49 @@ static FileInfo fetchLinkInfo(Sigar sigar, String name)

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;
}
}
8 changes: 4 additions & 4 deletions bindings/java/src/org/hyperic/sigar/test/TestFileInfo.java
Expand Up @@ -133,11 +133,11 @@ public void testCreate() throws Exception {
tmp.deleteOnExit();
traceln("TMP=" + file);

try {
// try {
//stat() mtime is in seconds, this happens to quick to detect change.
Thread.sleep(1000 * 1);
} catch (InterruptedException e) {
}
//Thread.sleep(1000 * 1);
// } catch (InterruptedException e) {
// }

try {
FileInfo info = sigar.getFileInfo(file);
Expand Down

0 comments on commit 47f01e0

Please sign in to comment.