Skip to content

Commit a7f49c6

Browse files
committed
ScriptInfo: do not mix datestamp into the version
At the time I wrote that code, I was mainly concerned with ensuring that generated version strings do not clash. However, there are compelling reasons to avoid "false negatives" as well (two scripts which are actually the same, but end up with differing version strings). When mixing in the datestamp with the hash, a false negative will happen if the script's last modified date is not preserved when copied between systems. This makes data provenance more difficult, because two systems may have identical installations content-wise, but different version strings due to timestamp skew. So, let's keep it simpler: use the content hash if available (i.e.: if the script contents can be read), and the datestamp only if not.
1 parent aef704c commit a7f49c6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main/java/org/scijava/script/ScriptInfo.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,15 @@ public String getLocation() {
322322
public String getVersion() {
323323
final File file = new File(path);
324324
if (!file.exists()) return null; // no version for non-existent script
325-
final Date lastModified = FileUtils.getModifiedTime(file);
326-
final String datestamp =
327-
new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(lastModified);
328325
try {
329-
final String hash = DigestUtils.bestHex(FileUtils.readFile(file));
330-
return datestamp + "-" + hash;
326+
return DigestUtils.bestHex(FileUtils.readFile(file));
331327
}
332328
catch (final IOException exc) {
333329
log.error(exc);
334330
}
331+
final Date lastModified = FileUtils.getModifiedTime(file);
332+
final String datestamp =
333+
new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(lastModified);
335334
return datestamp;
336335
}
337336

0 commit comments

Comments
 (0)