mirror of
https://github.com/mitb-archive/filebot
synced 2025-01-08 12:28:04 -05:00
Make sure to preserve Last Modified date after renamed and xattr-tagging files (and use last modified date for abuse sanity checks as well to reduce false positives)
This commit is contained in:
parent
2fc9bd0644
commit
7213220c86
@ -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) {
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user