package org.security.common.util;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.HashSet;
import java.util.Set;

/**
 * @author ：wzf
 * @apiNote ：设置文件权限
 * @since ：Created in 2022/9/29 16:41
 */

public class SetFilePermission {

	public static void setPermission(String filePath) throws IOException {
		Path path = Paths.get(filePath);
		Set<PosixFilePermission> perms = new HashSet<>();
		perms.add(PosixFilePermission.OWNER_WRITE);
		perms.add(PosixFilePermission.OWNER_READ);
		perms.add(PosixFilePermission.OWNER_EXECUTE);
		perms.add(PosixFilePermission.GROUP_WRITE);
		perms.add(PosixFilePermission.GROUP_READ);
		perms.add(PosixFilePermission.GROUP_EXECUTE);
//		perms.add(PosixFilePermission.OTHERS_WRITE);
		perms.add(PosixFilePermission.OTHERS_READ);
//		perms.add(PosixFilePermission.OTHERS_EXECUTE);
		Files.setPosixFilePermissions(path,perms);
	}
}
