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

int [] net::sf::jftp::net::FtpConnection::getPermissions (  )  [inline]

Sort the permissions an return an array.

The Array should be in sync with the other sort*-Methods

Parameters:
file The file containing the raw server listing, usually Settings.ls_out
Returns:
An int-array of sizes containing W, R or DENIED for each file

Implements net::sf::jftp::net::BasicConnection.

Definition at line 504 of file FtpConnection.java.

References net::sf::jftp::net::FtpConstants::DENIED, getOsType(), net::sf::jftp::net::FtpConstants::R, username, and net::sf::jftp::net::FtpConstants::W.

Referenced by exists().

    {
        try
        {
            currentPerms.removeAllElements();
            
            for(int i=0; i<currentListing.size(); i++)
            {
                String tmp = (String) currentListing.get(i);

                // ------------- VMS override -------------------
                if(getOsType().indexOf("VMS") >= 0)
                {
                    if(tmp.indexOf(";") < 0)
                    {
                        continue;
                    }

                    currentPerms.add("r");

                    continue;
                }

                // ------------- MVS override -------------------
                if(getOsType().indexOf("MVS") >= 0)
                {
                    if(tmp.startsWith("Volume"))
                    {
                        continue;
                    }

                    currentPerms.add("r");

                    continue;
                }

                // ------------------------------------------------

                StringTokenizer to = new StringTokenizer(tmp.trim(), " ", false);

                if(!(to.countTokens() > 3) ||
                       (tmp.startsWith("/") && (tmp.indexOf("denied") > 0)))
                {
                    continue;
                }

                tmp = to.nextToken();

                if(tmp.length() != 10)
                {
                    //System.out.println(tmp + " - e");
                    return null; // exotic bug, hardlinks are not found or something ("/bin/ls: dir: no such file or directy" in ls output) - we have no permissions then
                }

                char ur = tmp.charAt(1);
                char uw = tmp.charAt(2);
                char ar = tmp.charAt(7);
                char aw = tmp.charAt(8);

                to.nextToken();

                String user = to.nextToken();

                //System.out.println(""+ur+":"+ar+":"+tmp);
                if(aw == 'w')
                {
                  currentPerms.add("w");
                }
                else if(user.equals(username) && (uw == 'w'))
                {
                  currentPerms.add("w");
                }
                else if(ar == 'r')
                {
                  currentPerms.add("r");
                }
                else if(user.equals(username) && (ur == 'r'))
                {
                  currentPerms.add("r");
                }
                else
                {
                    //System.out.println(ur+":"+ar+":"+user+":"+username+":");
                  currentPerms.add("n");
                }
            }
        }
        catch(Exception ex)
        {
            Log.debug(ex.toString() + " @FtpConnection::getPermissions#1");
        }

        int[] ret = new int[currentPerms.size()];
        
        for(int i=0; i<currentPerms.size(); i++) {
            String fx = (String) currentPerms.get(i);
            
            if(fx.equals("w"))
            {
                  ret[i] = W;
            }
            else if(fx.equals("n"))
            {
                  ret[i] = DENIED;
            }
            else
            {
                  ret[i] = R;
            }
            //System.out.println(ret[i]);
        }
    
        return ret;
    }


Generated by  Doxygen 1.6.0   Back to index