Skip to content

Commit

Permalink
Fix #2930
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Feb 28, 2023
1 parent 5c4daae commit 22dbaac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Fixed:
the process (#2897)
* Fixed `filename` getter being called multiple time in
`output.file` (#2842)
* Fixed default directory permissions in `output.*.hls`
operators (#2930)
* Space trim in interactive variables set on telnet (#2785)
* Fixed internal streaming logic in `max_duration` and `crossfade`.
* Make sure that there's at most one metadata at any given
Expand Down
24 changes: 14 additions & 10 deletions src/outputs/hls_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ let hls_proto kind =
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 @@ -123,10 +131,6 @@ let hls_proto kind =
"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 @@ -255,10 +259,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 @@ -273,7 +278,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 @@ -432,7 +437,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
let kind = Kind.of_kind (Encoder.kind_of_format (List.hd streams).format) in
object (self)
inherit
Expand All @@ -456,7 +460,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 @@ -511,7 +515,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
20 changes: 20 additions & 0 deletions tests/regression/GH2926.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%include "test.liq"

tmp_dir = file.temp_dir("tmp", "dir")
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)

0 comments on commit 22dbaac

Please sign in to comment.