Add callback for delete operation.
[cyberduck.git] / source / ch / cyberduck / core / ftp / FTPMoveFeature.java
blob906a67ddf453ac5fe99a90801b0d3630417b9f1b
1 package ch.cyberduck.core.ftp;
3 /*
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * feedback@cyberduck.ch
21 import ch.cyberduck.core.DisabledLoginCallback;
22 import ch.cyberduck.core.Path;
23 import ch.cyberduck.core.exception.BackgroundException;
24 import ch.cyberduck.core.exception.NotfoundException;
25 import ch.cyberduck.core.features.Delete;
26 import ch.cyberduck.core.features.Move;
28 import org.apache.log4j.Logger;
30 import java.io.IOException;
31 import java.util.Collections;
33 /**
34 * @version $Id$
36 public class FTPMoveFeature implements Move {
37 private static final Logger log = Logger.getLogger(FTPMoveFeature.class);
39 private FTPSession session;
41 public FTPMoveFeature(final FTPSession session) {
42 this.session = session;
45 @Override
46 public boolean isSupported(final Path file) {
47 return true;
50 @Override
51 public void move(final Path file, final Path renamed, boolean exists, final Delete.Callback callback) throws BackgroundException {
52 try {
53 if(exists) {
54 final Delete delete = session.getFeature(Delete.class);
55 try {
56 delete.delete(Collections.singletonList(renamed), new DisabledLoginCallback(), callback);
58 catch(NotfoundException e) {
59 log.warn(String.format("Failure deleting file %s %s", renamed, e));
62 if(!session.getClient().rename(file.getAbsolute(), renamed.getAbsolute())) {
63 throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString());
66 catch(IOException e) {
67 throw new FTPExceptionMappingService().map("Cannot rename {0}", e, file);