All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.eliux.mega.cmd.MegaCmdRemove Maven / Gradle / Ivy

Go to download

Java client library that works on top of MEGAcmd to provide access to the services of Mega.nz

There is a newer version: 1.6.2
Show newest version
package com.github.eliux.mega.cmd;

import com.github.eliux.mega.error.MegaException;

public class MegaCmdRemove extends AbstractMegaCmdRunnerWithParams {

    private final String remotePath;

    private boolean recursivelyDeleted;

    private boolean errorIgnoredIfAbsent;

    public MegaCmdRemove(String remotePath) {
        this.remotePath = remotePath;
    }

    public String getRemotePath() {
        return remotePath;
    }

    @Override
    String cmdParams() {
        StringBuilder cmdParamsBuilder
                = new StringBuilder("-f ");  //Never asks

        if (recursivelyDeleted) {
            cmdParamsBuilder.append("-r ");
        }

        return cmdParamsBuilder.append(remotePath).toString();
    }

    @Override
    public void run() {
        try {
            super.run();
        } catch (MegaException ex) {
            if (!errorIgnoredIfAbsent) {
                throw ex;
            }
        }
    }

    @Override
    public String getCmd() {
        return "rm";
    }

    public MegaCmdRemove deleteRecursively() {
        recursivelyDeleted = true;
        return this;
    }

    public MegaCmdRemove deleteRecursivelyDisabled() {
        recursivelyDeleted = false;
        return this;
    }

    public boolean isRecursivelyDeleted() {
        return recursivelyDeleted;
    }

    public MegaCmdRemove ignoreErrorIfNotPresent() {
        errorIgnoredIfAbsent = true;
        return this;
    }

    public MegaCmdRemove reportErrorIfNotPresent() {
        errorIgnoredIfAbsent = false;
        return this;
    }

    public boolean isErrorIgnoredIfAbsent() {
        return errorIgnoredIfAbsent;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy