9
9
10
10
import java .util .Scanner ;
11
11
import java .io .File ;
12
+ import java .nio .file .Path ;
12
13
13
14
14
15
public class Filesystem {
15
- public static void main (String [] args ) {
16
+ public static void main (String [] argv ) {
16
17
Scanner scanner = new Scanner (System .in );
17
18
18
- String argument = "" ;
19
+ String a1 = "" ;
20
+ String a2 = "" ;
19
21
final String prompt = "Jfs> " ;
20
22
21
23
System .out .print (prompt );
22
24
23
25
while (scanner .hasNextLine ()) {
24
26
String input = scanner .nextLine ();
25
27
26
- String [] inputArray = input .split (" " );
27
- String command = inputArray [0 ];
28
+ String [] args = input .split (" " );
29
+ String command = args [0 ];
28
30
29
- if (inputArray .length > 1 ) {
30
- argument = inputArray [1 ];
31
- } else {
32
- argument = "" ;
31
+ if (args .length > 1 ) {
32
+ a1 = args [1 ];
33
+ }
34
+ if (args .length > 2 ) {
35
+ a2 = args [2 ];
33
36
}
34
37
35
38
if (command .equals ("exit" ) || command .equals ("q" ) || command .equals ("\u0004 " )) {
36
39
break ;
37
40
} else if (command .equals ("java_version" )) {
38
41
System .out .println (System .getProperty ("java.version" ));
39
42
} else if (command .equals ("absolute" )) {
40
- System .out .println (absolute (argument ));
43
+ System .out .println (absolute (a1 ));
44
+ } else if (command .equals ("create_symlink" )) {
45
+ System .out .println (create_symlink (a1 , a2 ));
41
46
} else if (command .equals ("expanduser" )) {
42
- System .out .println (expanduser (argument ));
47
+ System .out .println (expanduser (a1 ));
43
48
} else if (command .equals ("canonical" )) {
44
- System .out .println (canonical (argument ));
49
+ System .out .println (canonical (a1 ));
45
50
} else if (command .equals ("parent" )) {
46
- System .out .println (parent (argument ));
51
+ System .out .println (parent (a1 ));
47
52
} else if (command .equals ("root" )) {
48
- System .out .println (root (argument ));
53
+ System .out .println (root (a1 ));
49
54
} else if (command .equals ("is_absolute" )) {
50
- System .out .println (is_absolute (argument ));
55
+ System .out .println (is_absolute (a1 ));
51
56
} else if (command .equals ("is_exe" )) {
52
- System .out .println (is_exe (argument ));
57
+ System .out .println (is_exe (a1 ));
53
58
} else if (command .equals ("is_readable" )) {
54
- System .out .println (is_readable (argument ));
59
+ System .out .println (is_readable (a1 ));
55
60
} else if (command .equals ("ram_free" )) {
56
61
System .out .println (ram_free ());
57
62
} else if (command .equals ("cpu_count" )) {
@@ -71,6 +76,18 @@ public static String absolute(String path) {
71
76
return f .getAbsolutePath ();
72
77
}
73
78
79
+ public static Boolean create_symlink (String target , String link ) {
80
+ Path t = new File (target ).toPath ();
81
+ Path l = new File (link ).toPath ();
82
+ try {
83
+ java .nio .file .Files .createSymbolicLink (l , t );
84
+ return true ;
85
+ } catch (java .io .IOException e ) {
86
+ System .err .println (e );
87
+ return false ;
88
+ }
89
+ }
90
+
74
91
public static String expanduser (String path ) {
75
92
if (path .startsWith ("~" ))
76
93
return System .getProperty ("user.home" ) + path .substring (1 );
0 commit comments