Просмотр исходного кода

Merge pull request #9780 from id/fix-ensure-no-colon-in-filenames

fix: ensure no colon in filenames
Ivan Dyachkov 3 лет назад
Родитель
Сommit
430b0a03d4

+ 5 - 5
.github/workflows/run_jmeter_tests.yaml

@@ -126,7 +126,7 @@ jobs:
     - name: check logs
       run: |
         if cat jmeter_logs/${{ matrix.scripts_type }}.jtl | grep -e '<failure>true</failure>' > /dev/null 2>&1; then
-          echo "check logs filed"
+          echo "check logs failed"
           exit 1
         fi
     - uses: actions/upload-artifact@v3
@@ -235,7 +235,7 @@ jobs:
     - name: check logs
       run: |
         if cat jmeter_logs/${{ matrix.scripts_type }}_${{ matrix.pgsql_tag }}.jtl | grep -e '<failure>true</failure>' > /dev/null 2>&1; then
-          echo "check logs filed"
+          echo "check logs failed"
           exit 1
         fi
     - uses: actions/upload-artifact@v3
@@ -341,7 +341,7 @@ jobs:
     - name: check logs
       run: |
         if cat jmeter_logs/${{ matrix.scripts_type }}_${{ matrix.mysql_tag }}.jtl | grep -e '<failure>true</failure>' > /dev/null 2>&1; then
-          echo "check logs filed"
+          echo "check logs failed"
           exit 1
         fi
     - uses: actions/upload-artifact@v3
@@ -439,7 +439,7 @@ jobs:
     - name: check logs
       run: |
         if cat jmeter_logs/${{ matrix.scripts_type }}.jtl | grep -e '<failure>true</failure>' > /dev/null 2>&1; then
-          echo "check logs filed"
+          echo "check logs failed"
           exit 1
         fi
     - uses: actions/upload-artifact@v3
@@ -531,7 +531,7 @@ jobs:
     - name: check logs
       run: |
         if cat jmeter_logs/${{ matrix.scripts_type }}_${{ matrix.mysql_tag }}.jtl | grep -e '<failure>true</failure>' > /dev/null 2>&1; then
-          echo "check logs filed"
+          echo "check logs failed"
           exit 1
         fi
     - uses: actions/upload-artifact@v3

+ 2 - 2
apps/emqx/src/emqx_authentication_config.erl

@@ -327,9 +327,9 @@ atom(Bin) -> binary_to_existing_atom(Bin, utf8).
 certs_dir(ChainName, ConfigOrID) ->
     DirName = dir(ChainName, ConfigOrID),
     SubDir = iolist_to_binary(filename:join(["authn", DirName])),
-    binary:replace(SubDir, <<":">>, <<"-">>, [global]).
+    emqx_misc:safe_filename(SubDir).
 
 dir(ChainName, ID) when is_binary(ID) ->
-    binary:replace(iolist_to_binary([to_bin(ChainName), "-", ID]), <<":">>, <<"-">>);
+    emqx_misc:safe_filename(iolist_to_binary([to_bin(ChainName), "-", ID]));
 dir(ChainName, Config) when is_map(Config) ->
     dir(ChainName, authenticator_id(Config)).

+ 10 - 1
apps/emqx/src/emqx_misc.erl

@@ -55,7 +55,8 @@
     readable_error_msg/1,
     safe_to_existing_atom/1,
     safe_to_existing_atom/2,
-    pub_props_to_packet/1
+    pub_props_to_packet/1,
+    safe_filename/1
 ]).
 
 -export([
@@ -708,3 +709,11 @@ pub_props_to_packet(Properties) ->
             true
     end,
     maps:filtermap(F, Properties).
+
+%% fix filename by replacing characters which could be invalid on some filesystems
+%% with safe ones
+-spec safe_filename(binary() | unicode:chardata()) -> binary() | [unicode:chardata()].
+safe_filename(Filename) when is_binary(Filename) ->
+    binary:replace(Filename, <<":">>, <<"-">>, [global]);
+safe_filename(Filename) when is_list(Filename) ->
+    string:replace(Filename, ":", "-", all).

+ 2 - 1
apps/emqx_bridge/src/emqx_bridge_resource.erl

@@ -216,7 +216,8 @@ recreate(Type, Name, Conf, Opts) ->
     ).
 
 create_dry_run(Type, Conf0) ->
-    TmpPath = iolist_to_binary(["bridges-create-dry-run:", emqx_misc:gen_id(8)]),
+    TmpPath0 = iolist_to_binary(["bridges-create-dry-run:", emqx_misc:gen_id(8)]),
+    TmpPath = emqx_misc:safe_filename(TmpPath0),
     Conf = emqx_map_lib:safe_atom_key_map(Conf0),
     case emqx_connector_ssl:convert_certs(TmpPath, Conf) of
         {error, Reason} ->

+ 3 - 2
apps/emqx_resource/src/emqx_resource_worker.erl

@@ -871,8 +871,9 @@ queue_count(Q) ->
     replayq:count(Q).
 
 disk_queue_dir(Id, Index) ->
-    QDir = binary_to_list(Id) ++ ":" ++ integer_to_list(Index),
-    filename:join([emqx:data_dir(), "resource_worker", node(), QDir]).
+    QDir0 = binary_to_list(Id) ++ ":" ++ integer_to_list(Index),
+    QDir = filename:join([emqx:data_dir(), "resource_worker", node(), QDir0]),
+    emqx_misc:safe_filename(QDir).
 
 ensure_flush_timer(Data = #{tref := undefined, batch_time := T}) ->
     Ref = make_ref(),

+ 1 - 0
changes/v5.0.15/fix-9780.en.md

@@ -0,0 +1 @@
+When creating disk queue directory for resource worker, substitute ':' with '-' in worker id.

+ 1 - 0
changes/v5.0.15/fix-9780.zh.md

@@ -0,0 +1 @@
+在为资源缓存进程创建磁盘队列目录时,在ID中用 '-' 代替 ':'。