[ https://issues.apache.org/jira/browse/TWILL-188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15436192#comment-15436192 ]
ASF GitHub Bot commented on TWILL-188: -------------------------------------- Github user chtyim commented on a diff in the pull request: https://github.com/apache/twill/pull/3#discussion_r76174543 --- Diff: twill-common/src/main/java/org/apache/twill/filesystem/LocalLocation.java --- @@ -255,4 +288,53 @@ public int hashCode() { public String toString() { return file.toString(); } + + /** + * Ensures the given {@link File} is a directory. If it doesn't exist, it will be created. + */ + private void ensureDirectory(File dir) throws IOException { + // Check, create, check to resolve race conditions if there are concurrent creation of the directory. + if (!dir.isDirectory() && !dir.mkdirs() && !dir.isDirectory()) { + throw new IOException("Failed to create directory " + dir); + } + } + + /** + * Parses the given permission to a set of {@link PosixFilePermission}. + * + * @param permission the permission as passed to the {@link #createNew(String)} or {@link #getOutputStream(String)} + * methods. + * @return a new set of {@link PosixFilePermission}. + */ + private Set<PosixFilePermission> parsePermissions(String permission) { + Set<PosixFilePermission> permissions; + if (permission.length() == 3) { + permissions = parseNumericPermissions(permission); + } else if (permission.length() == 9) { + permissions = PosixFilePermissions.fromString(permission); + } else { + throw new IllegalArgumentException("Invalid permission " + permission + + ". Permission should either be a three digits or nine characters string."); + } + + return permissions; + } + + /** + * Parses a three digits UNIX numeric permission representation to a set of {@link PosixFilePermission}. + */ + private Set<PosixFilePermission> parseNumericPermissions(String permission) { + String posixPermission = ""; + for (int i = 0; i < 3; i++) { + int digit = permission.charAt(i) - '0'; + if (digit < 0 || digit > 7) { + throw new IllegalArgumentException("Invalid permission " + permission + + ". Only digits between 0-7 is allowed."); --- End diff -- fixed > LocationFactory should have options to accept permission for create > ------------------------------------------------------------------- > > Key: TWILL-188 > URL: https://issues.apache.org/jira/browse/TWILL-188 > Project: Apache Twill > Issue Type: Improvement > Reporter: Shankar Selvam > Assignee: Terence Yim > Fix For: 0.8.0 > > > Currently LocationFactory and Location API doesn't have a way to specify the > permission to use for creating the path. we need a way to specify the > permission for create and other operations on Location -- This message was sent by Atlassian JIRA (v6.3.4#6332)