Niklas,

I had proposed a change a while back to allow for new SITE commands. I have added quite a few using it: CHMOD, UTIME, DUAL [provides MD5 & SHA1 hashes on a file or all files in a directory], and some custom ones specific to my needs.

Maybe it can posted/added as an "extra" for people that would want the ability to add custom SITE commands? I would supply the ones above and a generic template on how to do it.

One of the key tasks is to detect the OS platform the service is running one and call the appropriate OS command shell & command. There was a good article about 7-8 years ago on this, not much has changed from the JVM perspective [sad].

Here is a snippet from the code:

            String osName = System.getProperty("os.name");
            String[] cmd = new String[3];

            if (osName.equals("Windows 95")) {
                cmd[0] = "command.com";
                cmd[1] = "/C";
                cmd[2] = cmdline;
            } else if (osName.contains("Windows")) {
                cmd[0] = "cmd.exe";
                cmd[1] = "/C";
                cmd[2] = cmdline;
            } else if (osName.equals("Linux")) {
                cmd[0] = "sh";
                cmd[1] = "-c";
                cmd[2] = cmdline;
            }

            Runtime rt = Runtime.getRuntime();

            // run the command
            Process proc = rt.exec(cmd);

The "cmdline" is a string that holds the actual command and it's parameters: "/bin/chmod 755 somefile". All error messages are passed back, works same as command line.

The commands could be separate jar files, or integrated with the main package, up to the developer. I personally like keeping them outside the main code, just specify the class path in the config file, and let the SITE cmd load it.

The SITE cmd uses two maps, the normal one that it uses now, and then a user map that has the add-on commands. It looks in one map then the other, taking into account a user may actually over-ride an existing SITE command.

Not sure what is the best way to get this code introduced? Maybe just post it somewhere and reference it?

Andy


Niklas Gustavsson wrote:
On Fri, Aug 22, 2008 at 1:31 PM, Loureiro, Gil <[EMAIL PROTECTED]> wrote:
I've seen that the SITE CHMOD command is not supported, that in the case of
my application is Ok because user should never change permission.

The reason for it not being supported is that Java does not currently
allow setting file permissions. There are some third-party libs that
could be investigated for this, but they will be dependent on the OS
so I'm a bit reluctant. Also, the upcoming new file API does allow for
setting file permissions, hopefully coming in Java 7.

But, if I create a new dir, from both fs or ftp, the permissions are always
rw for the owner, is it possible to set the default permission for a certain
user?

No, not at the moment. Patches welcome of course :-)

/niklas

Reply via email to