2 package org
.de
.metux
.util
;
4 import java
.util
.Properties
;
5 import java
.io
.BufferedReader
;
6 import java
.io
.IOException
;
7 import java
.io
.InterruptedIOException
;
8 import java
.io
.InputStreamReader
;
13 // FIXME: parse the modes
14 public static boolean chmod(String fn
, String mode
)
16 return Exec
.exec_command(
18 ShellEscape
.filename(mode
)+
20 ShellEscape
.filename(fn
)
24 public static boolean cp(String source
, String dest
)
26 return cp(source
,dest
,null);
29 public static boolean cp(String source
, String dest
, String mode
)
31 if (dest
.endsWith("/"))
34 mkdir(PathNormalizer
.dirname(dest
));
36 if (!Exec
.exec_command(
38 ShellEscape
.filename(source
)+
40 ShellEscape
.filename(dest
)
44 if (!StrUtil
.isEmpty(mode
))
48 if (new File(dest
).isDirectory())
49 dir
= dest
+"/"+PathNormalizer
.basename(source
);
53 return chmod(dir
,mode
);
59 public static boolean mkdir(String dir
)
61 if ((dir
==null)||(dir
.length()==0))
64 File handle
= new File(dir
);
66 return handle
.isDirectory();
69 public static boolean mkdir(String dirs
[])
71 if ((dirs
==null)||(dirs
.length
==0))
73 for (int x
=0; x
<dirs
.length
; x
++)
78 public static void symlink(String target
, String name
)
80 // System.err.println("TARGET="+target);
81 // System.err.println("NAME="+name);
85 ShellEscape
.filename(target
)+
87 ShellEscape
.filename(name
);
88 System
.err
.println("symlink# "+cmd
);
92 public static void rm(String fn
)
94 new File(fn
).delete();
97 public static String
getcwd()
99 File f
= new File(".");
100 String filePath
= f
.getAbsolutePath();
101 int dotAt
= filePath
.lastIndexOf(".");
102 return (new String(filePath
.substring(0,dotAt
)));
105 public static File
getcwd_handle()
107 return new File(getcwd());
110 public static boolean chdir(String dirname
)
112 File d
= new File(dirname
);
113 if (!d
.isDirectory())
116 System
.setProperty("user.dir", d
.getAbsolutePath());
120 public static String
md5(File f
)
122 String out
= _run_cmd("md5sum "+f
.getAbsolutePath()+" 2>&1");
124 throw new RuntimeException("md5: exec didnt give result for: "+f
);
126 String s
[] = StrSplit
.split(out
);
129 throw new RuntimeException("md5: got no result for: "+f
);
134 static private String
_run_cmd(String cmdline
)
136 String cmds
[] = cmds
= new String
[3];
139 cmds
[0] = "/bin/bash";
141 cmds
[2] = cmdline
+" 2>&1";
143 // System.err.println("_run_cmd(): "+cmdline);
147 process
= Runtime
.getRuntime().exec
151 new File(System
.getProperty("user.dir"))
154 BufferedReader stdout
= new BufferedReader(new InputStreamReader(process
.getInputStream()));
158 while ((line
=stdout
.readLine())!=null)
163 catch (IOException e
)
165 throw new RuntimeException(e
);
168 // catch (InterruptedException e)
170 // callback.error("InterruptedException in Stage::exec()"+e);