public Path createNewFile(File newFile, String posixFileAttributes) throws IOException { return createNewFile(newFile.toPath(), posixFileAttributes); }
public Path createNewFile(Path newFile, String posixFileAttributes) throws IOException { Set<PosixFilePermission> permissions = posixFileAttributes == null ? null : PosixFilePermissions.fromString(posixFileAttributes); return createNewFile(newFile, permissions ); }
@Override protected void onCreate() { super.onCreate(); File file = new File(_path); if (!file.exists()) { File parent = file.getAbsoluteFile().getParentFile(); if (!parent.exists() && !parent.mkdirs()) { throw new IllegalConfigurationException(String.format("Cannot create groups file at '%s'",_path)); } try { String posixFileAttributes = getContextValue(String.class, SystemConfig.POSIX_FILE_PERMISSIONS); new FileHelper().createNewFile(file, posixFileAttributes); } catch (IOException e) { throw new IllegalConfigurationException(String.format("Cannot create groups file at '%s'", _path), e); } } }
public void writeFileSafely(Path targetFile, Path backupFile, Path tmpFile, BaseAction<File, IOException> write) throws IOException { Files.deleteIfExists(tmpFile); Files.deleteIfExists(backupFile); Set<PosixFilePermission> permissions = null; if (Files.exists(targetFile) && isPosixFileSystem(targetFile)) { permissions = Files.getPosixFilePermissions(targetFile); } tmpFile = createNewFile(tmpFile, permissions); write.performAction(tmpFile.toFile()); atomicFileMoveOrReplace(targetFile, backupFile); if (permissions != null) { Files.setPosixFilePermissions(backupFile, permissions); } atomicFileMoveOrReplace(tmpFile, targetFile); Files.deleteIfExists(tmpFile); Files.deleteIfExists(backupFile); }
@Override protected void onCreate() { super.onCreate(); File passwordFile = new File(_path); if (!passwordFile.exists()) { try { Path path = new FileHelper().createNewFile(passwordFile, getContextValue(String.class, SystemConfig.POSIX_FILE_PERMISSIONS)); if (!Files.exists(path)) { throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path)); } } catch (IOException e) { throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path), e); } } }
storeFile = _fileHelper.createNewFile(storeFile, posixFileAttributes); getSerialisationObjectMapper().writeValue(storeFile.toFile(), initialData);