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
|
package io.github.jshipit;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
public class SysUtils {
interface CLibrary extends Library {
public int chmod(String path, int mode);
}
public void chmod(String path, int mode) {
CLibrary libc = (CLibrary) Native.load("c", CLibrary.class);
libc.chmod(path, mode);
}
public void overlayMount(String[] lower, String upper, String target, String work) {
if (Platform.isLinux()) {
ProcessBuilder pb = new ProcessBuilder("unshare", "--user", "--map-root-user", "--mount", "mount", "-t", "overlay", "overlay", "-o", "lowerdir="+String.join(":", lower)+",upperdir="+upper+",workdir="+work, target);
pb.inheritIO();
try {
Process p = pb.start();
p.waitFor();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
System.out.println("Platform not supported.");
System.out.println("mount -t overlay overlay -o lowerdir="+String.join(":", lower)+",upperdir="+upper+",workdir="+work+" "+target);
}
}
}
|