diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index a652599f..b268f839 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -606,8 +606,8 @@ public class CmdlineOperations implements CmdlineInterface { } // do not allow abuse of online databases by repeatedly processing the same files - if (matches != null && renameAction.canRevert() && source.length() > 0 && equalsFileContent(source, destination)) { - throw new CmdlineException(String.format("Failed to process [%s] because [%s] is an exact copy and already exists", source, destination)); + if (matches != null && renameAction.canRevert() && source.length() > 0 && equalsLastModified(source, destination, 2000) && equalsFileContent(source, destination)) { + throw new CmdlineException(String.format("Failed to process [%s] because [%s] is an exact copy and already exists [Last-Modified: %tc]", source, destination, destination.lastModified())); } // delete existing destination path if necessary @@ -683,6 +683,13 @@ public class CmdlineOperations implements CmdlineInterface { } } } + + // preserve Last Modified date + log.forEach((source, destination) -> { + if (destination != null) { + destination.setLastModified(source.lastModified()); + } + }); } protected File nextAvailableIndexedName(File file) { diff --git a/source/net/filebot/util/FileUtilities.java b/source/net/filebot/util/FileUtilities.java index 59ad6777..6b082367 100644 --- a/source/net/filebot/util/FileUtilities.java +++ b/source/net/filebot/util/FileUtilities.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import java.util.TreeSet; +import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -289,21 +290,22 @@ public final class FileUtilities { return false; } - // must not be a folder - if (a.isDirectory() || b.isDirectory()) { - return false; - } - - // must be equal byte by byte - try { - return FileUtils.contentEquals(a, b); - } catch (Exception e) { - log.warning(cause(e)); + // must be a regular file and must be equal byte by byte + if (a.isFile() && b.isFile()) { + try { + return FileUtils.contentEquals(a, b); + } catch (Exception e) { + log.log(Level.WARNING, e, e::getMessage); + } } return false; } + public static boolean equalsLastModified(File a, File b, int granularity) { + return a.lastModified() / granularity == b.lastModified() / granularity; + } + /** * Pattern used for matching file extensions. *