@@ -186,6 +186,27 @@ ngx_rtmp_hls_chain2buffer(ngx_buf_t *out, ngx_chain_t *in, size_t skip)
186
186
}
187
187
188
188
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
+
189
210
static ngx_int_t
190
211
ngx_rtmp_hls_update_playlist (ngx_rtmp_session_t * s )
191
212
{
@@ -209,21 +230,17 @@ ngx_rtmp_hls_update_playlist(ngx_rtmp_session_t *s)
209
230
NGX_FILE_TRUNCATE , NGX_FILE_DEFAULT_ACCESS );
210
231
211
232
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 */
216
233
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 )
220
236
{
221
- ngx_log_debug1 (NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
222
- "hls: creating target folder: '%V'" , & hacf -> path );
223
- ++ nretry ;
237
+ nretry ++ ;
224
238
goto retry ;
225
239
}
226
240
241
+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , ngx_errno ,
242
+ "hls: open failed: '%V'" , & ctx -> playlist_bak );
243
+
227
244
return NGX_ERROR ;
228
245
}
229
246
@@ -457,6 +474,7 @@ ngx_rtmp_hls_next_frag(ngx_rtmp_session_t *s)
457
474
{
458
475
ngx_rtmp_hls_app_conf_t * hacf ;
459
476
ngx_rtmp_hls_ctx_t * ctx ;
477
+ ngx_int_t nretry ;
460
478
461
479
ctx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_hls_module );
462
480
@@ -500,10 +518,22 @@ ngx_rtmp_hls_next_frag(ngx_rtmp_session_t *s)
500
518
501
519
ngx_str_set (& ctx -> file .name , "hls" );
502
520
521
+ nretry = 0 ;
522
+
523
+ retry :
524
+
503
525
ctx -> file .fd = ngx_open_file (ctx -> stream .data , NGX_FILE_WRONLY ,
504
526
NGX_FILE_TRUNCATE , NGX_FILE_DEFAULT_ACCESS );
505
527
506
528
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
+
507
537
ngx_log_error (NGX_LOG_ERR , s -> connection -> log , ngx_errno ,
508
538
"hls: error creating fragment file" );
509
539
return ;
0 commit comments