Search in sources :

Example 1 with DeleteData

use of com.bonree.brfs.disknode.server.handler.data.DeleteData in project BRFS by zhangnianli.

the class DeleteMessageHandler method handle.

@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    try {
        String filePath = diskContext.getConcreteFilePath(msg.getPath());
        Map<String, String> params = msg.getParams();
        LOG.info("delete params--{}", params);
        DeleteData data = new DeleteData();
        data.setForceClose(params.containsKey("force") ? true : false);
        data.setRecursive(params.containsKey("recursive") ? true : false);
        LOG.info("deleting path[{}], force[{}], recursive[{}]", filePath, data.isForceClose(), data.isRecursive());
        File targetFile = new File(filePath);
        if (targetFile.isFile()) {
            try {
                closeFile(targetFile, data.isForceClose());
                result.setSuccess(true);
            } catch (Exception e) {
                result.setSuccess(false);
                result.setCause(e);
                return;
            }
        } else {
            try {
                closeDir(targetFile, data.isRecursive(), data.isForceClose());
                result.setSuccess(true);
            } catch (Exception e) {
                result.setSuccess(false);
                result.setCause(e);
                return;
            }
        }
    } catch (Exception e) {
        LOG.error("delete message error", e);
        result.setSuccess(false);
    } finally {
        callback.completed(result);
    }
}
Also used : DeleteData(com.bonree.brfs.disknode.server.handler.data.DeleteData) HandleResult(com.bonree.brfs.common.net.http.HandleResult) File(java.io.File)

Aggregations

HandleResult (com.bonree.brfs.common.net.http.HandleResult)1 DeleteData (com.bonree.brfs.disknode.server.handler.data.DeleteData)1 File (java.io.File)1