1ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair/* 2ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * Copyright 2008 the original author or authors. 3ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * 4ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * you may not use this file except in compliance with the License. 6ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * You may obtain a copy of the License at 7ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * 8ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * http://www.apache.org/licenses/LICENSE-2.0 9ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * 10ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * Unless required by applicable law or agreed to in writing, software 11ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * distributed under the License is distributed on an "AS IS" BASIS, 12ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * See the License for the specific language governing permissions and 14ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * limitations under the License. 15ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair */ 16ef13cb2302efe30bdff397e11aae379cbb419b9bchrismairpackage org.mockftpserver.fake.command; 17ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 18ef13cb2302efe30bdff397e11aae379cbb419b9bchrismairimport org.mockftpserver.core.command.Command; 19ef13cb2302efe30bdff397e11aae379cbb419b9bchrismairimport org.mockftpserver.core.command.ReplyCodes; 20ef13cb2302efe30bdff397e11aae379cbb419b9bchrismairimport org.mockftpserver.core.session.Session; 21ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 22ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair/** 23ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * CommandHandler for the DELE command. Handler logic: 24ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * <ol> 25ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * <li>If the user has not logged in, then reply with 530</li> 26ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * <li>If the required pathname parameter is missing, then reply with 501</li> 273736b2d78b2d799ad9318e5295e2204c21e21a44chrismair * <li>If the pathname parameter does not specify an existing file then reply with 550</li> 28f7ca9deffcf7588769ebf32b4cea41210e4794a4chrismair * <li>If the current user does not have write access to the parent directory, then reply with 550</li> 293736b2d78b2d799ad9318e5295e2204c21e21a44chrismair * <li>Otherwise, delete the named file and reply with 250</li> 30ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * </ol> 31ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * The supplied pathname may be absolute or relative to the current directory. 32ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * 33ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair * @author Chris Mair 342a0a3f946dba517a01cc26278f905156857c9c91chrismair * @version $Revision$ - $Date$ 35ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair */ 36ef13cb2302efe30bdff397e11aae379cbb419b9bchrismairpublic class DeleCommandHandler extends AbstractFakeCommandHandler { 37ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 38ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair protected void handle(Command command, Session session) { 39ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair verifyLoggedIn(session); 40ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair String path = getRealPath(session, command.getRequiredParameter(0)); 41ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 42ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair this.replyCodeForFileSystemException = ReplyCodes.READ_FILE_ERROR; 43ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair verifyFileSystemCondition(getFileSystem().isFile(path), path, "filesystem.isNotAFile"); 44ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 45ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair // User must have write permission to the parent directory 46ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair verifyWritePermission(session, getFileSystem().getParent(path)); 47ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 48ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair getFileSystem().delete(path); 49ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair sendReply(session, ReplyCodes.DELE_OK, "dele", list(path)); 50ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair } 51ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair 52ef13cb2302efe30bdff397e11aae379cbb419b9bchrismair}