// Path: src/com/zlab/datFM/swiftp/MediaUpdater.java
// public enum MediaUpdater {
//     INSTANCE;
//     
//     private final static String TAG = MediaUpdater.class.getSimpleName();
// 
//     // the systembroadcast to remount the media is only done after a little while (5s)
//     private static Timer sTimer = new Timer();
// 
//     public static void notifyFileCreated(String path) {
//         if (Defaults.do_mediascanner_notify) {
//             Log.d(TAG, "Notifying others about new file: " + path);
//             Context context = FtpServerApp.getAppContext();
//             MediaScannerConnection.scanFile(context, new String[]{path}, null,
//                     new MediaScannerConnection.OnScanCompletedListener() {
//                         @Override
//                         public void onScanCompleted(String path, Uri uri) {
//                         }
//                     });
//         }
//     }
// 
//     public static void notifyFileDeleted(String path) {
//         // The media mounted broadcast is very taxing on the system, so we only do this
//         // if for 5 seconds there was no same request, otherwise we wait again.
//         if (Defaults.do_mediascanner_notify) {
//             Log.d(TAG, "Notifying others about deleted file: " + path);
//             // the systembroadcast might have been requested already, cancel if so
//             sTimer.cancel();
//             // that timer is of no value any more, create a new one
//             sTimer = new Timer();
//             // and in 5s let it send the broadcast, might never hapen if before
//             // that time it gets canceled by this code path
//             sTimer.schedule(new TimerTask() {
//                 @Override
//                 public void run() {
//                     Log.d(TAG, "Sending ACTION_MEDIA_MOUNTED broadcast");
//                     final Context context = FtpServerApp.getAppContext();
//                     context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
//                             .parse("file://" + Environment.getExternalStorageDirectory())));
//                 }
//             }, 5000);
//         }
//     }
// 
// }


import com.zlab.datFM.swiftp.MediaUpdater;
import java.io.File;
import android.util.Log;
/*
Copyright 2009 David Revell

This file is part of SwiFTP.

SwiFTP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SwiFTP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SwiFTP.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.zlab.datFM.swiftp.server;



public class CmdDELE extends FtpCmd implements Runnable {
    private static final String TAG = CmdDELE.class.getSimpleName();

    protected String input;

    public CmdDELE(SessionThread sessionThread, String input) {
        super(sessionThread);
        this.input = input;
    }

    @Override
    public void run() {
        Log.d(TAG, "DELE executing");
        String param = getParameter(input);
        File storeFile = inputPathToChrootedFile(sessionThread.getWorkingDir(), param);
        String errString = null;
        if (violatesChroot(storeFile)) {
            errString = "550 Invalid name or chroot violation\r\n";
        } else if (storeFile.isDirectory()) {
            errString = "550 Can't DELE a directory\r\n";
        } else if (!storeFile.delete()) {
            errString = "450 Error deleting file\r\n";
        }

        if (errString != null) {
            sessionThread.writeString(errString);
            Log.i(TAG, "DELE failed: " + errString.trim());
        } else {
            sessionThread.writeString("250 File successfully deleted\r\n");
// Path: src/com/zlab/datFM/swiftp/MediaUpdater.java
// public enum MediaUpdater {
//     INSTANCE;
//     
//     private final static String TAG = MediaUpdater.class.getSimpleName();
// 
//     // the systembroadcast to remount the media is only done after a little while (5s)
//     private static Timer sTimer = new Timer();
// 
//     public static void notifyFileCreated(String path) {
//         if (Defaults.do_mediascanner_notify) {
//             Log.d(TAG, "Notifying others about new file: " + path);
//             Context context = FtpServerApp.getAppContext();
//             MediaScannerConnection.scanFile(context, new String[]{path}, null,
//                     new MediaScannerConnection.OnScanCompletedListener() {
//                         @Override
//                         public void onScanCompleted(String path, Uri uri) {
//                         }
//                     });
//         }
//     }
// 
//     public static void notifyFileDeleted(String path) {
//         // The media mounted broadcast is very taxing on the system, so we only do this
//         // if for 5 seconds there was no same request, otherwise we wait again.
//         if (Defaults.do_mediascanner_notify) {
//             Log.d(TAG, "Notifying others about deleted file: " + path);
//             // the systembroadcast might have been requested already, cancel if so
//             sTimer.cancel();
//             // that timer is of no value any more, create a new one
//             sTimer = new Timer();
//             // and in 5s let it send the broadcast, might never hapen if before
//             // that time it gets canceled by this code path
//             sTimer.schedule(new TimerTask() {
//                 @Override
//                 public void run() {
//                     Log.d(TAG, "Sending ACTION_MEDIA_MOUNTED broadcast");
//                     final Context context = FtpServerApp.getAppContext();
//                     context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
//                             .parse("file://" + Environment.getExternalStorageDirectory())));
//                 }
//             }, 5000);
//         }
//     }
// 
// }


// Path: src/com/zlab/datFM/swiftp/server/CmdDELE.java
import com.zlab.datFM.swiftp.MediaUpdater;
import java.io.File;
import android.util.Log;

/*
Copyright 2009 David Revell

This file is part of SwiFTP.

SwiFTP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SwiFTP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SwiFTP.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.zlab.datFM.swiftp.server;



public class CmdDELE extends FtpCmd implements Runnable {
    private static final String TAG = CmdDELE.class.getSimpleName();

    protected String input;

    public CmdDELE(SessionThread sessionThread, String input) {
        super(sessionThread);
        this.input = input;
    }

    @Override
    public void run() {
        Log.d(TAG, "DELE executing");
        String param = getParameter(input);
        File storeFile = inputPathToChrootedFile(sessionThread.getWorkingDir(), param);
        String errString = null;
        if (violatesChroot(storeFile)) {
            errString = "550 Invalid name or chroot violation\r\n";
        } else if (storeFile.isDirectory()) {
            errString = "550 Can't DELE a directory\r\n";
        } else if (!storeFile.delete()) {
            errString = "450 Error deleting file\r\n";
        }

        if (errString != null) {
            sessionThread.writeString(errString);
            Log.i(TAG, "DELE failed: " + errString.trim());
        } else {
            sessionThread.writeString("250 File successfully deleted\r\n");
            MediaUpdater.notifyFileDeleted(storeFile.getPath());