Logo Search packages:      
Sourcecode: jftp version File versions  Download package

int net::sf::jftp::net::FtpConnection::cleanDir ( String  dir,
String  path 
) [inline, private]

recursive delete remote directory

Definition at line 1882 of file FtpConnection.java.

References chdirNoRefresh(), net::sf::jftp::net::FtpConstants::GENERIC_FAILED, isSymlink(), list(), parseSymlink(), net::sf::jftp::net::FtpConstants::PERMISSION_DENIED, net::sf::jftp::net::FtpConstants::REMOVE_SUCCESSFUL, removeFileOrDir(), and sortLs().

Referenced by removeFileOrDir().

    {
        if(dir.equals(""))
        {
            return 0;
        }

        if(!dir.endsWith("/"))
        {
            dir = dir + "/";
        }

        String remoteDir = StringUtils.removeStart(dir, path);

        String oldDir = pwd;
        chdirNoRefresh(pwd + remoteDir);

        try
        {
            list();
        }
        catch(IOException ex)
        {
            // probably we don't have permission to ls here
            return PERMISSION_DENIED;
        }

        String[] tmp = sortLs();
        chdirNoRefresh(oldDir);

        if(tmp == null)
        {
            return GENERIC_FAILED;
        }

        for(int i = 0; i < tmp.length; i++)
        {
            Log.out("cleanDir: " + tmp);

            if(isSymlink(tmp[i]))
            {
                Log.debug("WARNING: Skipping symlink, remove failed.");
                Log.debug("This is necessary to prevent possible data loss when removing those symlinks.");

                tmp[i] = null;
            }

            if(tmp[i] != null)
            {
                tmp[i] = parseSymlink(tmp[i]);
            }

            if((tmp[i] == null) || tmp[i].equals("./") || tmp[i].equals("../"))
            {
                //System.out.println(tmp[i]+"\n\n\n");
                continue;
            }

            //System.out.println(tmp[i]);
            //pause(500);
            if(tmp[i].endsWith("/"))
            {
                //   System.out.println(dir);
                cleanDir(dir + tmp[i], path);

                int x = removeFileOrDir(dir + tmp[i]);

                if(x < 0)
                {
                    return x;
                }
            }
            else
            {
                //   System.out.println(dir+tmp[i]);
                int x = removeFileOrDir(dir + tmp[i]);

                if(x < 0)
                {
                    return x;
                }
            }
        }

        return REMOVE_SUCCESSFUL;
    }


Generated by  Doxygen 1.6.0   Back to index