File: ChmodTest_Standalone.java

package info (click to toggle)
jython 2.7.2%2Brepack1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 62,676 kB
  • sloc: python: 640,908; java: 306,458; xml: 1,984; sh: 522; ansic: 126; makefile: 76
file content (57 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.python.util.install;

import java.io.File;
import java.io.IOException;

/**
 * Helper class to test of 'chmod' on different platforms
 */
public class ChmodTest_Standalone {

    private static String _mode = "755"; // default mode

    public static void main(String[] args) {
        // get mode from first argument, if present
        if (args.length > 0) {
            _mode = args[0];
        }

        // create an empty test file in the current directory
        String curdir = System.getProperty("user.dir");
        File testFile = new File(curdir, "chmod.test");
        String path = testFile.getAbsolutePath();
        if (!testFile.exists()) {
            try {
                if (!testFile.createNewFile()) {
                    System.err.println(getPrefix() + "unable to create file " + path);
                    System.exit(1);
                }
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }

        // apply the chmod command on the test file
        if (!testFile.exists()) {
            System.err.println(getPrefix() + "unable to create file " + path);
            System.exit(1);
        } else {
            String command[] = new String[] {"chmod", _mode, path};
            ChildProcess childProcess = new ChildProcess(command, 3000);
            childProcess.setDebug(true);
            int exitValue = childProcess.run();
            if (exitValue != 0) {
                System.err.println(getPrefix() + "error during chmod");
            } else {
                System.out.println(getPrefix() + "chmod command executed on " + path);
            }
            System.exit(exitValue);
        }
    }

    private static String getPrefix() {
        return "[ChmodTest_Standalone] ";
    }

}