1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.context.task;
21
22 import org.waarp.common.command.exception.Reply550Exception;
23 import org.waarp.common.file.FileUtils;
24 import org.waarp.common.logging.WaarpLogger;
25 import org.waarp.common.logging.WaarpLoggerFactory;
26 import org.waarp.openr66.context.R66Session;
27 import org.waarp.openr66.protocol.exception.OpenR66ProtocolSystemException;
28
29 import java.io.File;
30 import java.util.regex.Pattern;
31
32
33
34
35
36
37
38
39 public class LinkRenameTask extends AbstractTask {
40
41
42
43 private static final WaarpLogger logger =
44 WaarpLoggerFactory.getLogger(LinkRenameTask.class);
45 private static final Pattern COMPILE = Pattern.compile(" ");
46
47
48
49
50
51
52
53 public LinkRenameTask(final String argRule, final int delay,
54 final String argTransfer, final R66Session session) {
55 super(TaskType.LINKRENAME, delay, argRule, argTransfer, session);
56 }
57
58 @Override
59 public final void run() {
60 String finalname = argRule;
61 finalname = getReplacedValue(finalname, COMPILE.split(argTransfer));
62 logger.info("Move and Rename to {} with {}:{} and {}", finalname, argRule,
63 argTransfer, session);
64
65
66 final File from = session.getFile().getTrueFile();
67 final File to = new File(finalname);
68 try {
69 FileUtils.copy(from, to, false, false);
70 } catch (final Reply550Exception e1) {
71 logger.error(
72 "Copy and Rename to " + finalname + " with " + argRule + ':' +
73 argTransfer + " and " + session + ": {}", e1.getMessage());
74 futureCompletion.setFailure(new OpenR66ProtocolSystemException(e1));
75 return;
76 }
77 session.getRunner().setFileMoved(finalname, true);
78 futureCompletion.setSuccess();
79 }
80
81 }