1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.tasks;
18
19 import org.apache.commons.vfs2.Capability;
20 import org.apache.commons.vfs2.FileObject;
21 import org.apache.commons.vfs2.FileSystemException;
22 import org.apache.commons.vfs2.Selectors;
23
24
25
26
27
28
29
30 public class MoveTask extends CopyTask {
31 private boolean tryRename;
32
33
34
35
36
37
38 public void setTryRename(final boolean tryRename) {
39 this.tryRename = tryRename;
40 }
41
42
43
44
45 @Override
46 protected void handleOutOfDateFile(final FileObjectect.html#FileObject">FileObject srcFile, final FileObject destFile) throws FileSystemException {
47 if (!tryRename || !srcFile.canRenameTo(destFile)) {
48 super.handleOutOfDateFile(srcFile, destFile);
49
50 log("Deleting " + srcFile.getPublicURIString());
51 srcFile.delete(Selectors.SELECT_SELF);
52 } else {
53 log("Rename " + srcFile.getPublicURIString() + " to " + destFile.getPublicURIString());
54 srcFile.moveTo(destFile);
55 if (!isPreserveLastModified()
56 && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE)) {
57 destFile.getContent().setLastModifiedTime(System.currentTimeMillis());
58 }
59 }
60 }
61 }