Skip to content

Commit 9aa030f

Browse files
committed
fixed creating hls target folder
1 parent 6298aa7 commit 9aa030f

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

hls/ngx_rtmp_hls_module.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ ngx_rtmp_hls_chain2buffer(ngx_buf_t *out, ngx_chain_t *in, size_t skip)
186186
}
187187

188188

189+
static ngx_int_t
190+
ngx_rtmp_hls_create_parent_dir(ngx_rtmp_session_t *s)
191+
{
192+
ngx_rtmp_hls_app_conf_t *hacf;
193+
194+
hacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_hls_module);
195+
196+
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
197+
"hls: creating target folder: '%V'", &hacf->path);
198+
199+
if (ngx_create_dir(hacf->path.data, NGX_RTMP_HLS_DIR_ACCESS) == NGX_OK) {
200+
return NGX_OK;
201+
}
202+
203+
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
204+
"hls: error creating target folder: '%V'", &hacf->path);
205+
206+
return NGX_ERROR;
207+
}
208+
209+
189210
static ngx_int_t
190211
ngx_rtmp_hls_update_playlist(ngx_rtmp_session_t *s)
191212
{
@@ -209,21 +230,17 @@ ngx_rtmp_hls_update_playlist(ngx_rtmp_session_t *s)
209230
NGX_FILE_TRUNCATE, NGX_FILE_DEFAULT_ACCESS);
210231

211232
if (fd == NGX_INVALID_FILE) {
212-
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
213-
"hls: open failed: '%V'", &ctx->playlist_bak);
214-
215-
/* try to create parent folder */
216233

217-
if (nretry == 0 &&
218-
ngx_create_dir(hacf->path.data, NGX_RTMP_HLS_DIR_ACCESS) !=
219-
NGX_INVALID_FILE)
234+
if (ngx_errno == NGX_ENOENT && nretry == 0 &&
235+
ngx_rtmp_hls_create_parent_dir(s) == NGX_OK)
220236
{
221-
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
222-
"hls: creating target folder: '%V'", &hacf->path);
223-
++nretry;
237+
nretry++;
224238
goto retry;
225239
}
226240

241+
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
242+
"hls: open failed: '%V'", &ctx->playlist_bak);
243+
227244
return NGX_ERROR;
228245
}
229246

@@ -457,6 +474,7 @@ ngx_rtmp_hls_next_frag(ngx_rtmp_session_t *s)
457474
{
458475
ngx_rtmp_hls_app_conf_t *hacf;
459476
ngx_rtmp_hls_ctx_t *ctx;
477+
ngx_int_t nretry;
460478

461479
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_hls_module);
462480

@@ -500,10 +518,22 @@ ngx_rtmp_hls_next_frag(ngx_rtmp_session_t *s)
500518

501519
ngx_str_set(&ctx->file.name, "hls");
502520

521+
nretry = 0;
522+
523+
retry:
524+
503525
ctx->file.fd = ngx_open_file(ctx->stream.data, NGX_FILE_WRONLY,
504526
NGX_FILE_TRUNCATE, NGX_FILE_DEFAULT_ACCESS);
505527

506528
if (ctx->file.fd == NGX_INVALID_FILE) {
529+
530+
if (ngx_errno == NGX_ENOENT && nretry == 0 &&
531+
ngx_rtmp_hls_create_parent_dir(s) == NGX_OK)
532+
{
533+
nretry++;
534+
goto retry;
535+
}
536+
507537
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
508538
"hls: error creating fragment file");
509539
return;

0 commit comments

Comments
 (0)