mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-05-26 14:34:19 +00:00
Create temp file with limited permissions
This commit is contained in:
parent
f34b552054
commit
393e1efcd1
@ -21,9 +21,19 @@ import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
|
|||||||
public class IOUtils {
|
public class IOUtils {
|
||||||
|
|
||||||
public static File createTempFile() throws IOException {
|
public static File createTempFile() throws IOException {
|
||||||
final var tempFile = File.createTempFile("signal-cli_tmp_", ".tmp");
|
final var prefix = "signal-cli_tmp_";
|
||||||
tempFile.deleteOnExit();
|
final var suffix = ".tmp";
|
||||||
return tempFile;
|
try {
|
||||||
|
Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE);
|
||||||
|
var path = Files.createTempFile(prefix, suffix, PosixFilePermissions.asFileAttribute(perms));
|
||||||
|
var tempFile = path.toFile();
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
return tempFile;
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
|
final var tempFile = File.createTempFile(prefix, suffix);
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
return tempFile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] readFully(InputStream in) throws IOException {
|
public static byte[] readFully(InputStream in) throws IOException {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user