From f479bc88e1182822ccf221346baaa7e14ce5b4ed Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Wed, 15 May 2024 17:09:56 -0700 Subject: [PATCH] Bandaid fix for yt-dlp write issue --- lib/pinchflat/utils/cli_utils.ex | 12 +++++++++++- test/pinchflat/utils/cli_utils_test.exs | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/pinchflat/utils/cli_utils.ex b/lib/pinchflat/utils/cli_utils.ex index aee0dc8..2a82423 100644 --- a/lib/pinchflat/utils/cli_utils.ex +++ b/lib/pinchflat/utils/cli_utils.ex @@ -24,11 +24,12 @@ defmodule Pinchflat.Utils.CliUtils do def wrap_cmd(command, args, passthrough_opts \\ [], opts \\ []) do wrapper_command = Path.join(:code.priv_dir(:pinchflat), "cmd_wrapper.sh") actual_command = [command] ++ args + command_opts = set_command_opts() ++ passthrough_opts logging_arg_override = Keyword.get(opts, :logging_arg_override, Enum.join(args, " ")) Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}") - {output, status} = System.cmd(wrapper_command, actual_command, passthrough_opts) + {output, status} = System.cmd(wrapper_command, actual_command, command_opts) log_cmd_result(command, logging_arg_override, status, output) {output, status} @@ -81,4 +82,13 @@ defmodule Pinchflat.Utils.CliUtils do Logger.log(log_level, log_message) end + + defp set_command_opts do + # This resolves an issue where yt-dlp would attempt to write to a read-only directory + # if you scanned a new video with `--windows-filenames` enabled. Hopefully can be removed + # in the future. + [ + cd: Application.get_env(:pinchflat, :tmpfile_directory) + ] + end end diff --git a/test/pinchflat/utils/cli_utils_test.exs b/test/pinchflat/utils/cli_utils_test.exs index cda3102..a724b8e 100644 --- a/test/pinchflat/utils/cli_utils_test.exs +++ b/test/pinchflat/utils/cli_utils_test.exs @@ -7,6 +7,10 @@ defmodule Pinchflat.Utils.CliUtilsTest do test "delegates to System.cmd/3" do assert {"output\n", 0} = CliUtils.wrap_cmd("echo", ["output"]) end + + test "sets the current directory to the tmp dir" do + assert {"/tmp/test/tmpfiles\n", 0} = CliUtils.wrap_cmd("pwd", []) + end end describe "parse_options/1" do