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