Skip to content

Commit

Permalink
Fix HLS directory permissions. Fixes: #2930
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Feb 28, 2023
1 parent 3281c32 commit 781a9a2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/core/outputs/hls_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ let hls_proto frame_t =
Some "Number of segments per playlist." );
( "perm",
Lang.int_t,
Some (Lang.int 0o644),
Some (Lang.int 0o666),
Some
"Permission of the created files, up to umask. You can and should \
write this number in octal notation: 0oXXX. The default value is \
however displayed in decimal (0o666 = 6×8^2 + 4×8 + 4 = 412)." );
( "dir_perm",
Lang.int_t,
Some (Lang.int 0o777),
Some
"Permission of the directories if some have to be created, up to \
umask. Although you can enter values in octal notation (0oXXX) they \
will be displayed in decimal (for instance, 0o777 = 7×8^2 + 7×8 + 7 \
= 511)." );
( "on_file_change",
Lang.fun_t
[(false, "state", Lang.string_t); (false, "", Lang.string_t)]
Expand All @@ -115,10 +123,6 @@ let hls_proto frame_t =
"Location of the configuration file used to restart the output. \
Relative paths are assumed to be with regard to the directory for \
generated file." );
( "perms",
Lang.int_t,
Some (Lang.int 0o755),
Some "Default directory rights if created. Default: `0o755`" );
( "strict_persist",
Lang.bool_t,
Some (Lang.bool false),
Expand Down Expand Up @@ -247,10 +251,11 @@ class hls_output p =
let prefix = Lang.to_string (List.assoc "prefix" p) in
let directory = Lang.to_string (Lang.assoc "" 1 p) in
let perm = Lang.to_int (List.assoc "perm" p) in
let dir_perm = Lang.to_int (List.assoc "dir_perm" p) in
let () =
if (not (Sys.file_exists directory)) || not (Sys.is_directory directory)
then (
try Utils.mkdir ~perm directory
try Utils.mkdir ~perm:dir_perm directory
with exn ->
let bt = Printexc.get_raw_backtrace () in
Lang.raise_as_runtime ~bt ~kind:"file" exn)
Expand All @@ -265,7 +270,7 @@ class hls_output p =
else filename
in
let dir = Filename.dirname filename in
(try Utils.mkdir ~perm:0o777 dir
(try Utils.mkdir ~perm:dir_perm dir
with exn ->
raise
(Error.Invalid_value
Expand Down Expand Up @@ -420,7 +425,6 @@ class hls_output p =
let max_segments =
segments_per_playlist + Lang.to_int (List.assoc "segments_overhead" p)
in
let file_perm = Lang.to_int (List.assoc "perm" p) in
object (self)
inherit
Output.encoded
Expand All @@ -443,7 +447,7 @@ class hls_output p =

method private open_out filename =
let mode = [Open_wronly; Open_creat; Open_trunc] in
let oc = open_out_gen mode file_perm filename in
let oc = open_out_gen mode perm filename in
set_binary_mode_out oc true;
on_file_change ~state:`Opened filename;
oc
Expand Down Expand Up @@ -498,7 +502,7 @@ class hls_output p =
let () =
if (not (Sys.file_exists directory)) || not (Sys.is_directory directory)
then (
try Utils.mkdir ~perm directory
try Utils.mkdir ~perm:dir_perm directory
with exn ->
let bt = Printexc.get_raw_backtrace () in
Lang.raise_as_runtime ~bt ~kind:"file" exn)
Expand Down
18 changes: 18 additions & 0 deletions tests/regression/GH2926.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tmp_dir = file.temp_dir("tmp")
on_shutdown({file.rmdir(tmp_dir)})

def f() =
enc = %ffmpeg(format="mpegts",%audio(codec="aac"))
streams = [("enc", enc)]

output.file.hls(
fallible=true,
on_stop=test.pass,
persist_at="./config",
path.concat(tmp_dir, "hls"),
streams,
once(sine(duration=1.))
)
end

test.check(f)
13 changes: 13 additions & 0 deletions tests/regression/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@
(:run_test ../run_test.exe))
(action (run %{run_test} ffmpeg-copy-input-http.liq liquidsoap %{test_liq} ffmpeg-copy-input-http.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
GH2926.liq
../media/all_media_files
../../src/bin/liquidsoap.exe
(source_tree ../../src/libs)
(:stdlib ../../src/libs/stdlib.liq)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} GH2926.liq liquidsoap %{test_liq} GH2926.liq)))

(rule
(alias citest)
(package liquidsoap)
Expand Down

0 comments on commit 781a9a2

Please sign in to comment.