+ copy files with attributes
* xattr will only be set on destination files, not source files
This commit is contained in:
parent
4b15736faf
commit
4354dc2fd6
|
@ -219,19 +219,6 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
// add matches from other files that are linked via filenames
|
// add matches from other files that are linked via filenames
|
||||||
matches.addAll(derivateMatches);
|
matches.addAll(derivateMatches);
|
||||||
|
|
||||||
// first write all the metadata if xattr is enabled
|
|
||||||
if (useExtendedFileAttributes()) {
|
|
||||||
try {
|
|
||||||
for (Match<File, ?> match : matches) {
|
|
||||||
if (match.getCandidate() instanceof Episode) {
|
|
||||||
MediaDetection.storeMetaInfo(match.getValue(), match.getCandidate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
CLILogger.warning("Failed to write xattr: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// map old files to new paths by applying formatting and validating filenames
|
// map old files to new paths by applying formatting and validating filenames
|
||||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||||
|
|
||||||
|
@ -245,7 +232,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
// rename episodes
|
// rename episodes
|
||||||
Analytics.trackEvent("CLI", "Rename", "Episode", renameMap.size());
|
Analytics.trackEvent("CLI", "Rename", "Episode", renameMap.size());
|
||||||
return renameAll(renameMap, renameAction, conflictAction);
|
return renameAll(renameMap, renameAction, conflictAction, matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Match<File, Object>> matchEpisodes(Collection<File> files, Collection<Episode> episodes, boolean strict) throws Exception {
|
private List<Match<File, Object>> matchEpisodes(Collection<File> files, Collection<Episode> episodes, boolean strict) throws Exception {
|
||||||
|
@ -475,19 +462,6 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// first write all the metadata if xattr is enabled
|
|
||||||
if (useExtendedFileAttributes()) {
|
|
||||||
try {
|
|
||||||
for (Match<File, ?> match : matches) {
|
|
||||||
if (match.getCandidate() instanceof Movie) {
|
|
||||||
MediaDetection.storeMetaInfo(match.getValue(), match.getCandidate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
CLILogger.warning("Failed to write xattr: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// map old files to new paths by applying formatting and validating filenames
|
// map old files to new paths by applying formatting and validating filenames
|
||||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||||
|
|
||||||
|
@ -501,7 +475,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
// rename movies
|
// rename movies
|
||||||
Analytics.trackEvent("CLI", "Rename", "Movie", renameMap.size());
|
Analytics.trackEvent("CLI", "Rename", "Movie", renameMap.size());
|
||||||
return renameAll(renameMap, renameAction, conflictAction);
|
return renameAll(renameMap, renameAction, conflictAction, matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<File> renameMusic(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, MusicIdentificationService service) throws Exception {
|
public List<File> renameMusic(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, MusicIdentificationService service) throws Exception {
|
||||||
|
@ -538,7 +512,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
// rename movies
|
// rename movies
|
||||||
Analytics.trackEvent("CLI", "Rename", "AudioTrack", renameMap.size());
|
Analytics.trackEvent("CLI", "Rename", "AudioTrack", renameMap.size());
|
||||||
return renameAll(renameMap, renameAction, conflictAction);
|
return renameAll(renameMap, renameAction, conflictAction, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<File, Object> getContext(final Collection<Match<File, ?>> matches) {
|
private Map<File, Object> getContext(final Collection<Match<File, ?>> matches) {
|
||||||
|
@ -574,7 +548,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<File> renameAll(Map<File, File> renameMap, RenameAction renameAction, ConflictAction conflictAction) throws Exception {
|
public List<File> renameAll(Map<File, File> renameMap, RenameAction renameAction, ConflictAction conflictAction, List<Match<File, ?>> matches) throws Exception {
|
||||||
if (renameMap.isEmpty()) {
|
if (renameMap.isEmpty()) {
|
||||||
throw new Exception(format("[%s] Unable to process any files", renameAction));
|
throw new Exception(format("[%s] Unable to process any files", renameAction));
|
||||||
}
|
}
|
||||||
|
@ -631,6 +605,24 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write metadata into xattr if xattr is enabled
|
||||||
|
if (matches != null && useExtendedFileAttributes()) {
|
||||||
|
try {
|
||||||
|
for (Match<File, ?> match : matches) {
|
||||||
|
File file = match.getValue();
|
||||||
|
Object meta = match.getCandidate();
|
||||||
|
if (renameMap.containsKey(file) && meta != null) {
|
||||||
|
File destination = resolveDestination(file, renameMap.get(file), false);
|
||||||
|
if (destination.isFile()) {
|
||||||
|
MediaDetection.storeMetaInfo(destination, meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
CLILogger.warning("Failed to write xattr: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// new file names
|
// new file names
|
||||||
List<File> destinationList = new ArrayList<File>();
|
List<File> destinationList = new ArrayList<File>();
|
||||||
for (Entry<File, File> it : renameLog) {
|
for (Entry<File, File> it : renameLog) {
|
||||||
|
|
|
@ -77,26 +77,15 @@ class RenameAction extends AbstractAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<File, File> renameMap = checkRenamePlan(validate(model.getRenameMap(), window), window);
|
Map<File, File> renameMap = checkRenamePlan(validate(model.getRenameMap(), window), window);
|
||||||
StandardRenameAction action = (StandardRenameAction) getValue(RENAME_ACTION);
|
|
||||||
if (renameMap.isEmpty()) {
|
if (renameMap.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start processing
|
// start processing
|
||||||
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
List<Match<Object, File>> matches = new ArrayList<Match<Object, File>>(model.matches());
|
||||||
|
StandardRenameAction action = (StandardRenameAction) getValue(RENAME_ACTION);
|
||||||
|
|
||||||
// first write all the metadata if xattr is enabled
|
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
if (useExtendedFileAttributes()) {
|
|
||||||
try {
|
|
||||||
for (Match<Object, File> match : model.matches()) {
|
|
||||||
if (renameMap.containsKey(match.getCandidate()) && match.getValue() != null) {
|
|
||||||
MediaDetection.storeMetaInfo(match.getCandidate(), match.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useNativeShell() && isNativeActionSupported(action)) {
|
if (useNativeShell() && isNativeActionSupported(action)) {
|
||||||
RenameJob renameJob = new NativeRenameJob(renameMap, NativeRenameAction.valueOf(action.name()));
|
RenameJob renameJob = new NativeRenameJob(renameMap, NativeRenameAction.valueOf(action.name()));
|
||||||
|
@ -124,6 +113,24 @@ class RenameAction extends AbstractAction {
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write metadata into xattr if xattr is enabled
|
||||||
|
if (useExtendedFileAttributes()) {
|
||||||
|
try {
|
||||||
|
for (Match<Object, File> match : matches) {
|
||||||
|
File file = match.getCandidate();
|
||||||
|
Object meta = match.getValue();
|
||||||
|
if (renameMap.containsKey(file) && meta != null) {
|
||||||
|
File destination = resolveDestination(file, renameMap.get(file), false);
|
||||||
|
if (destination.isFile()) {
|
||||||
|
MediaDetection.storeMetaInfo(destination, meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
// ignore, handled in rename worker
|
// ignore, handled in rename worker
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public final class FileUtilities {
|
||||||
} else {
|
} else {
|
||||||
// copy file
|
// copy file
|
||||||
try {
|
try {
|
||||||
java.nio.file.Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
java.nio.file.Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
|
||||||
} catch (LinkageError e) {
|
} catch (LinkageError e) {
|
||||||
org.apache.commons.io.FileUtils.copyFile(source, destination);
|
org.apache.commons.io.FileUtils.copyFile(source, destination);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue