2012-03-07 14:26:47 +00:00
|
|
|
|
2012-07-12 11:23:23 +00:00
|
|
|
package net.sourceforge.filebot;
|
2012-03-07 14:26:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.sourceforge.tuned.FileUtilities;
|
|
|
|
|
|
|
|
|
|
|
|
public enum StandardRenameAction implements RenameAction {
|
|
|
|
|
|
|
|
MOVE {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws Exception {
|
|
|
|
return FileUtilities.moveRename(from, to);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
COPY {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws Exception {
|
|
|
|
return FileUtilities.copyAs(from, to);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-08 05:11:06 +00:00
|
|
|
KEEPLINK {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws Exception {
|
2012-07-20 03:38:47 +00:00
|
|
|
File destionation = FileUtilities.resolveDestination(from, to, true);
|
2012-03-08 05:11:06 +00:00
|
|
|
|
|
|
|
// move file and the create a symlink to the new location via NIO.2
|
|
|
|
try {
|
|
|
|
java.nio.file.Files.move(from.toPath(), destionation.toPath());
|
|
|
|
java.nio.file.Files.createSymbolicLink(from.toPath(), destionation.toPath());
|
|
|
|
} catch (LinkageError e) {
|
|
|
|
throw new Exception("Unsupported Operation: move, createSymbolicLink");
|
|
|
|
}
|
|
|
|
|
|
|
|
return destionation;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-07 14:26:47 +00:00
|
|
|
SYMLINK {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws Exception {
|
2012-07-20 03:38:47 +00:00
|
|
|
File destionation = FileUtilities.resolveDestination(from, to, true);
|
2012-03-07 14:26:47 +00:00
|
|
|
|
|
|
|
// create symlink via NIO.2
|
|
|
|
try {
|
|
|
|
java.nio.file.Files.createSymbolicLink(destionation.toPath(), from.toPath());
|
|
|
|
} catch (LinkageError e) {
|
|
|
|
throw new Exception("Unsupported Operation: createSymbolicLink");
|
|
|
|
}
|
|
|
|
|
|
|
|
return destionation;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
HARDLINK {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws Exception {
|
2012-07-20 03:38:47 +00:00
|
|
|
File destionation = FileUtilities.resolveDestination(from, to, true);
|
2012-03-07 14:26:47 +00:00
|
|
|
|
|
|
|
// create hardlink via NIO.2
|
|
|
|
try {
|
|
|
|
java.nio.file.Files.createLink(destionation.toPath(), from.toPath());
|
|
|
|
} catch (LinkageError e) {
|
|
|
|
throw new Exception("Unsupported Operation: createLink");
|
|
|
|
}
|
|
|
|
|
|
|
|
return destionation;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-17 04:14:09 +00:00
|
|
|
RENAME {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws IOException {
|
|
|
|
// rename only the filename
|
|
|
|
File dest = new File(from.getParentFile(), to.getName());
|
|
|
|
|
|
|
|
if (!from.renameTo(dest))
|
|
|
|
throw new IOException("Rename failed: " + dest);
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-07 14:26:47 +00:00
|
|
|
TEST {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public File rename(File from, File to) throws IOException {
|
2012-07-20 03:38:47 +00:00
|
|
|
return FileUtilities.resolveDestination(from, to, false);
|
2012-03-07 14:26:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-08 15:35:23 +00:00
|
|
|
public String getDisplayName() {
|
|
|
|
switch (this) {
|
|
|
|
case MOVE:
|
|
|
|
return "Rename";
|
|
|
|
case COPY:
|
|
|
|
return "Copy";
|
|
|
|
case KEEPLINK:
|
|
|
|
return "Keeplink";
|
|
|
|
case SYMLINK:
|
|
|
|
return "Symlink";
|
|
|
|
case HARDLINK:
|
|
|
|
return "Hardlink";
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-07 14:26:47 +00:00
|
|
|
public static StandardRenameAction forName(String action) {
|
|
|
|
for (StandardRenameAction it : values()) {
|
|
|
|
if (it.name().equalsIgnoreCase(action))
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("Illegal rename action: " + action);
|
|
|
|
}
|
2013-02-08 15:35:23 +00:00
|
|
|
|
2012-03-07 14:26:47 +00:00
|
|
|
}
|