forked from sbt/sbt-native-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/javapackager-format
* master: Update README.md Replace chmod call More comprehensive tests Adding documentation FIX sbt#276 creating directories as necessary and specify top level dir and sadly realizing that apache commons compress is still the best bet Adding documentation, examples and tests. Initial refactoring on sbt#453 Revert "[fix sbt#472] /etc/default/<package-name> should be shell script setting envars" FIX sbt#489: Small fix in documentation Upgrading to java 7 and using posix nio API Conflicts: src/main/scala/com/typesafe/sbt/packager/jdkpackager/JDKPackagerHelper.scala
- Loading branch information
Showing
35 changed files
with
758 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
package com.typesafe.sbt | ||
package packager | ||
|
||
import java.io.File | ||
import sbt.Process | ||
import java.io.{ File, IOException } | ||
import java.nio.file.{ Paths, Files } | ||
import java.nio.file.attribute.{ PosixFilePermission, PosixFilePermissions } | ||
|
||
/** | ||
* Setting the file permissions | ||
*/ | ||
object chmod { | ||
|
||
/** | ||
* Using java 7 nio API to set the permissions. | ||
* | ||
* @param file | ||
* @param perms in octal format | ||
*/ | ||
def apply(file: File, perms: String): Unit = | ||
Process(Seq("chmod", perms, file.getAbsolutePath)).! match { | ||
case 0 => () | ||
case n => sys.error("Error running chmod " + perms + " " + file) | ||
} | ||
def safe(file: File, perms: String): Unit = | ||
try apply(file, perms) | ||
catch { | ||
case e: RuntimeException => () | ||
try { | ||
Files.setPosixFilePermissions(file.toPath, permissions(perms)) | ||
} catch { | ||
case e: IOException => sys.error("Error setting permissions " + perms + " on " + file.getAbsolutePath + ": " + e.getMessage) | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Converts a octal unix permission representation into | ||
* a java `PosiFilePermissions` compatible string. | ||
*/ | ||
object permissions { | ||
|
||
/** | ||
* @param perms in octal format | ||
* @return java 7 posix file permissions | ||
*/ | ||
def apply(perms: String): java.util.Set[PosixFilePermission] = PosixFilePermissions fromString convert(perms) | ||
|
||
def convert(perms: String): String = { | ||
require(perms.length == 4 || perms.length == 3, s"Permissions must have 3 or 4 digits, got [$perms]") | ||
// ignore setuid/setguid/sticky bit | ||
val i = if (perms.length == 3) 0 else 1 | ||
val user = Character getNumericValue (perms charAt i) | ||
val group = Character getNumericValue (perms charAt i + 1) | ||
val other = Character getNumericValue (perms charAt i + 2) | ||
|
||
asString(user) + asString(group) + asString(other) | ||
} | ||
|
||
private def asString(perm: Int): String = perm match { | ||
case 0 => "---" | ||
case 1 => "--x" | ||
case 2 => "-w-" | ||
case 3 => "-wx" | ||
case 4 => "r--" | ||
case 5 => "r-x" | ||
case 6 => "rw-" | ||
case 7 => "rwx" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.