Skip to content

Commit

Permalink
Fixed support for gpg on android-linux (!)
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed Oct 25, 2023
1 parent 40cc9e6 commit 6ae7fae
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,32 @@ tshare /tmp/file3.txt -o hello.txt \x1b[1m# Uploaded as \"hello.txt\"\x1b[0m
stderr.write("\x1b[2K\r\x1b[1mEncrypting, please wait...\x1b[0m");

// Temporary and anonymous file, without even a name.
auto buffer = File.tmpfile();
auto pid = spawnProcess(["gpg", "-c", "--batch", "--passphrase", crypt, "-o", "-"], file, buffer, File.tmpfile(), string[string].init, Config.retainStdout);
File buffer;
File ignored;
bool needDelete = false;

try {
buffer = File.tmpfile();
ignored = File.tmpfile();
} catch(Exception e) {
// Probably we're on an android device, so we can't use tmpfile()
string tmpdir = environment.get("TMPDIR");
buffer = File(buildPath(tmpdir, "tmp-" ~ randomUUID().toString), "w+");
ignored = File(buildPath(tmpdir, "ignored-" ~ randomUUID().toString), "w+");
needDelete = true;
}

// Clean up tmp files on exit if needed
scope(exit)
{
if (needDelete)
{
remove(buffer.name);
remove(ignored.name);
}
}

auto pid = spawnProcess(["gpg", "-c", "--batch", "--passphrase", crypt, "-o", "-"], file, buffer, ignored, string[string].init, Config.retainStdout);

while(!pid.tryWait.terminated)
{
Expand Down

0 comments on commit 6ae7fae

Please sign in to comment.