From 86391a7f78770f543b492decb51527866a03fb4d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 8 Jan 2019 22:57:56 +0700 Subject: [PATCH] Force and Restore source last modified timestamp only if it was (possibly) changed by writing xattr metadata --- source/net/filebot/cli/CmdlineOperations.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index aa0b1482..3b60c605 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -676,20 +676,22 @@ public class CmdlineOperations implements CmdlineInterface { if (matches != null) { for (Match match : matches) { if (match.getCandidate() != null) { - File destination = log.get(match.getValue()); + File source = match.getValue(); + File destination = log.get(source); + if (destination != null && destination.isFile()) { + // remember Last Modified date + long timestamp = source.isFile() ? source.lastModified() : destination.lastModified(); + + // store xattr xattr.setMetaInfo(destination, match.getCandidate(), match.getValue().getName()); + + // restore Last Modified date + destination.setLastModified(timestamp); } } } } - - // preserve Last Modified date - log.forEach((source, destination) -> { - if (destination != null && destination.isFile() && source.exists()) { - destination.setLastModified(source.lastModified()); - } - }); } protected File nextAvailableIndexedName(File file) {