use of java.nio.file.attribute.PosixFilePermission in project drill by axbaretto.
the class HiveTestDataGenerator method createFileWithPermissions.
public static File createFileWithPermissions(File baseDir, String name) {
Set<PosixFilePermission> perms = Sets.newHashSet(PosixFilePermission.values());
File dir = new File(baseDir, name);
dir.mkdirs();
try {
Files.setPosixFilePermissions(dir.toPath(), perms);
} catch (IOException e) {
new RuntimeException(e);
}
return dir;
}
use of java.nio.file.attribute.PosixFilePermission in project eclipse-integration-commons by spring-projects.
the class OsUtils method posixFilePermissions.
public static Set<PosixFilePermission> posixFilePermissions(int mode) {
int mask = 1;
Set<PosixFilePermission> perms = EnumSet.noneOf(PosixFilePermission.class);
for (PosixFilePermission flag : decodeMap) {
if (flag != null && (mask & mode) != 0) {
perms.add(flag);
}
mask = mask << 1;
}
return perms;
}
use of java.nio.file.attribute.PosixFilePermission in project ASCIIGenome by dariober.
the class UcscFetch method checkOrCreateHgConfFile.
/**
* See if file $HOME/.hg.conf exists, if not create it. See also
* http://genomewiki.ucsc.edu/index.php/Genes_in_gtf_or_gff_format
* @throws IOException
*/
private static void checkOrCreateHgConfFile() throws IOException {
File hgConf = new File(System.getProperty("user.home"), ".hg.conf");
if (hgConf.isDirectory()) {
throw new RuntimeException(hgConf.getAbsolutePath() + " is a directory!");
}
if (!hgConf.exists()) {
String timeStamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(Calendar.getInstance().getTime());
BufferedWriter wr = new BufferedWriter(new FileWriter(hgConf));
wr.write("# " + timeStamp + " file created by " + ArgParse.PROG_NAME + "\n" + "db.host=genome-mysql.cse.ucsc.edu\n" + "db.user=genomep\n" + "db.password=password\n" + "central.db=hgcentral\n");
wr.close();
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
Files.setPosixFilePermissions(hgConf.toPath(), perms);
}
}
use of java.nio.file.attribute.PosixFilePermission in project ASCIIGenome by dariober.
the class UcscFetch method copyExecutableToLocal.
/**
* Copy genePredToGtf executables from jar to a local tmp dir. The version of genePredToGtf
* to copy is found by trial and error by executing them one by one until you find the one that returns
* the right exit code.
* @throws IOException
* @throws InterruptedException
*/
private File copyExecutableToLocal() throws IOException, InterruptedException {
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
for (String x : ARCHIT_DIR) {
File dest = new File(tmpdir, "genePredToGtf");
dest.deleteOnExit();
String src = UTILS_DIR + x + "/genePredToGtf";
this.copyResourceFile(src, dest.getAbsolutePath());
Files.setPosixFilePermissions(dest.toPath(), perms);
ProcessBuilder probuilder = new ProcessBuilder(dest.getAbsolutePath());
Process process = probuilder.start();
process.waitFor();
if (process.exitValue() == 255 || process.exitValue() == 0) {
return dest;
}
}
return null;
}
use of java.nio.file.attribute.PosixFilePermission in project universa by UniversaBlockchain.
the class CLIMain method getPrivateKey.
public static PrivateKey getPrivateKey() throws IOException {
if (privateKey == null) {
String keyFileName = prefs.get("privateKeyFile", null);
if (keyFileName != null) {
reporter.verbose("Loading private key from " + keyFileName);
try {
privateKey = new PrivateKey(Do.read(keyFileName));
} catch (IOException e) {
reporter.warning("can't read privte Key file: " + keyFileName);
}
}
if (privateKey == null) {
reporter.warning("\nUser private key is not set, generating new one.");
reporter.message("new private key has been generated");
privateKey = new PrivateKey(2048);
Path keysDir = Paths.get(System.getProperty("user.home") + "/.universa");
if (!Files.exists(keysDir)) {
reporter.verbose("creating new keys directory: " + keysDir.toString());
final Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwx------");
final FileAttribute<Set<PosixFilePermission>> ownerOnly = PosixFilePermissions.asFileAttribute(perms);
try {
Files.createDirectory(keysDir, ownerOnly);
} catch (java.lang.UnsupportedOperationException e) {
// Windows must die
Files.createDirectory(keysDir);
// this operation is not supported:
// Files.setPosixFilePermissions(keysDir, perms);
System.out.println("* Warning: can't set permissions on keys directory on windows");
System.out.println("* it is strongly recommended to restrict access to it manually\n");
}
}
Path keyFile = keysDir.resolve("main.private.unikey");
try (OutputStream out = Files.newOutputStream(keyFile)) {
out.write(privateKey.pack());
}
try {
final Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-------");
Files.setPosixFilePermissions(keyFile, perms);
} catch (UnsupportedOperationException e) {
System.out.println("* Warning: can't set permissions on key file on windows.");
System.out.println("* it is strongly recommended to restrict access to it manually\n");
}
prefs.put("privateKeyFile", keyFile.toString());
report("new private key has just been generated and stored to the " + keysDir);
}
}
return privateKey;
}
Aggregations