* follow symlinks implicitly
This commit is contained in:
parent
4354dc2fd6
commit
d63fca6787
|
@ -1,29 +1,32 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot;
|
package net.sourceforge.filebot;
|
||||||
|
|
||||||
|
import static java.nio.file.Files.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.attribute.UserDefinedFileAttributeView;
|
import java.nio.file.attribute.UserDefinedFileAttributeView;
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class MetaAttributeView extends AbstractMap<String, String> {
|
public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
|
|
||||||
private final UserDefinedFileAttributeView attributeView;
|
private final UserDefinedFileAttributeView attributeView;
|
||||||
private final Charset encoding;
|
private final Charset encoding;
|
||||||
|
|
||||||
|
public MetaAttributeView(File file) throws IOException {
|
||||||
public MetaAttributeView(File file) {
|
Path path = file.toPath();
|
||||||
attributeView = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class);
|
while (isSymbolicLink(path)) {
|
||||||
encoding = Charset.forName("UTF-8");
|
path = readSymbolicLink(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attributeView = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
|
||||||
|
encoding = Charset.forName("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(Object key) {
|
public String get(Object key) {
|
||||||
|
@ -38,7 +41,6 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String put(String key, String value) {
|
public String put(String key, String value) {
|
||||||
try {
|
try {
|
||||||
|
@ -53,7 +55,6 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
return null; // since we don't know the old value
|
return null; // since we don't know the old value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Entry<String, String>> entrySet() {
|
public Set<Entry<String, String>> entrySet() {
|
||||||
try {
|
try {
|
||||||
|
@ -67,7 +68,6 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
try {
|
try {
|
||||||
|
@ -79,7 +79,6 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
try {
|
try {
|
||||||
|
@ -89,7 +88,6 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
try {
|
try {
|
||||||
|
@ -99,35 +97,29 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class AttributeEntry implements Entry<String, String> {
|
private class AttributeEntry implements Entry<String, String> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
||||||
public AttributeEntry(String name) {
|
public AttributeEntry(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return get(name);
|
return get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String setValue(String value) {
|
public String setValue(String value) {
|
||||||
return put(name, value);
|
return put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getKey() + "=" + getValue();
|
return getKey() + "=" + getValue();
|
||||||
|
|
|
@ -1252,6 +1252,7 @@ public class MediaDetection {
|
||||||
public static void storeMetaInfo(File file, Object model) {
|
public static void storeMetaInfo(File file, Object model) {
|
||||||
// only for Episode / Movie objects
|
// only for Episode / Movie objects
|
||||||
if ((model instanceof Episode || model instanceof Movie) && file.exists()) {
|
if ((model instanceof Episode || model instanceof Movie) && file.exists()) {
|
||||||
|
try {
|
||||||
MetaAttributes xattr = new MetaAttributes(file);
|
MetaAttributes xattr = new MetaAttributes(file);
|
||||||
|
|
||||||
// set creation date to episode / movie release date
|
// set creation date to episode / movie release date
|
||||||
|
@ -1280,7 +1281,9 @@ public class MediaDetection {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set xattr: " + e.getMessage());
|
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set xattr: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
Logger.getLogger(MediaDetection.class.getClass().getName()).warning(t.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.media;
|
package net.sourceforge.filebot.media;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -13,7 +11,6 @@ import net.sourceforge.filebot.MetaAttributeView;
|
||||||
import com.cedarsoftware.util.io.JsonReader;
|
import com.cedarsoftware.util.io.JsonReader;
|
||||||
import com.cedarsoftware.util.io.JsonWriter;
|
import com.cedarsoftware.util.io.JsonWriter;
|
||||||
|
|
||||||
|
|
||||||
public class MetaAttributes {
|
public class MetaAttributes {
|
||||||
|
|
||||||
private static final String FILENAME_KEY = "filename";
|
private static final String FILENAME_KEY = "filename";
|
||||||
|
@ -22,18 +19,15 @@ public class MetaAttributes {
|
||||||
private final BasicFileAttributeView fileAttributeView;
|
private final BasicFileAttributeView fileAttributeView;
|
||||||
private final MetaAttributeView metaAttributeView;
|
private final MetaAttributeView metaAttributeView;
|
||||||
|
|
||||||
|
public MetaAttributes(File file) throws IOException {
|
||||||
public MetaAttributes(File file) {
|
|
||||||
this.metaAttributeView = new MetaAttributeView(file);
|
this.metaAttributeView = new MetaAttributeView(file);
|
||||||
this.fileAttributeView = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class);
|
this.fileAttributeView = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setCreationDate(long millis) throws IOException {
|
public void setCreationDate(long millis) throws IOException {
|
||||||
fileAttributeView.setTimes(null, null, FileTime.fromMillis(millis));
|
fileAttributeView.setTimes(null, null, FileTime.fromMillis(millis));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getCreationDate(long time) {
|
public long getCreationDate(long time) {
|
||||||
try {
|
try {
|
||||||
return fileAttributeView.readAttributes().creationTime().toMillis();
|
return fileAttributeView.readAttributes().creationTime().toMillis();
|
||||||
|
@ -42,27 +36,22 @@ public class MetaAttributes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setOriginalName(String name) {
|
public void setOriginalName(String name) {
|
||||||
metaAttributeView.put(FILENAME_KEY, name);
|
metaAttributeView.put(FILENAME_KEY, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getOriginalName() {
|
public String getOriginalName() {
|
||||||
return metaAttributeView.get(FILENAME_KEY);
|
return metaAttributeView.get(FILENAME_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setObject(Object object) {
|
public void setObject(Object object) {
|
||||||
metaAttributeView.put(METADATA_KEY, JsonWriter.toJson(object));
|
metaAttributeView.put(METADATA_KEY, JsonWriter.toJson(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object getObject() {
|
public Object getObject() {
|
||||||
return JsonReader.toJava(metaAttributeView.get(METADATA_KEY));
|
return JsonReader.toJava(metaAttributeView.get(METADATA_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
metaAttributeView.remove(FILENAME_KEY);
|
metaAttributeView.remove(FILENAME_KEY);
|
||||||
metaAttributeView.remove(METADATA_KEY);
|
metaAttributeView.remove(METADATA_KEY);
|
||||||
|
|
Loading…
Reference in New Issue