Skip to content

Commit 49ef423

Browse files
committed
Fix use of binary string in database_cache_file option
1 parent 329f5c9 commit 49ef423

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [2.3.10] - 2024-07-24
8+
9+
### Fixed
10+
11+
- use of binary string in `database_cache_file` option
12+
713
## [2.3.9] - 2024-07-20
814

915
### Added

src/locus_filesystem_load.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}.
8585
-export_type([success/0]).
8686

87-
-type path() :: nonempty_string().
87+
-type path() :: file:filename_all().
8888
-export_type([path/0]).
8989

9090
-record(state, {

src/locus_filesystem_store.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
{finished, {error, term()}}.
6262
-export_type([msg/0]).
6363

64-
-type path() :: nonempty_string().
64+
-type path() :: file:filename_all().
6565
-export_type([path/0]).
6666

6767
-record(state, {
@@ -156,7 +156,7 @@ handle_write(State) ->
156156
do_write(State) ->
157157
#state{path = Path, content = Content, modified_on = ModificationDT} = State,
158158
TmpSuffix = ".tmp." ++ integer_to_list(rand:uniform(1 bsl 32), 36),
159-
TmpPath = Path ++ TmpSuffix,
159+
TmpPath = unicode:characters_to_list([Path, TmpSuffix]),
160160
FileInfoMod = #file_info{ mtime = ModificationDT },
161161

162162
ok = filelib:ensure_dir(Path),

src/locus_loader.erl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
{update_period, milliseconds_interval()} |
9090
{error_retries, error_retry_behaviour()} |
9191
no_cache |
92-
{database_cache_file, file:filename()}.
92+
{database_cache_file, file:filename_all()}.
9393
-export_type([loader_opt/0]).
9494

9595
-type milliseconds_interval() :: pos_integer().
@@ -152,7 +152,7 @@
152152
error_retry_behaviour :: error_retry_behaviour(),
153153
error_retry_behaviour_applies_after_readiness :: boolean(),
154154
use_cache :: boolean(),
155-
database_cache_file :: file:filename() | undefined
155+
database_cache_file :: file:filename_all() | undefined
156156
}).
157157
-type settings() :: #settings{}.
158158

@@ -342,7 +342,7 @@ validate_loader_opts(MixedOpts, FetcherOpts) ->
342342
% Ensure directory exists
343343
Dirname = filename:dirname(File),
344344
(
345-
has_extenstion(File, ["gz", "mmdb"])
345+
has_extension(File, ["gz", "mmdb"])
346346
and
347347
filelib:is_dir(Dirname)
348348
)
@@ -466,7 +466,7 @@ schedule_update(Interval, State)
466466
NewTimer = erlang:send_after(Interval, self(), begin_update),
467467
State#state{ update_timer = NewTimer }.
468468

469-
-spec cached_database_path(state()) -> nonempty_string().
469+
-spec cached_database_path(state()) -> file:filename_all().
470470
cached_database_path(#state{
471471
settings = #settings{
472472
database_cache_file = DatabaseCacheFile
@@ -475,7 +475,6 @@ cached_database_path(#state{
475475
)
476476
when DatabaseCacheFile =/= undefined ->
477477
DatabaseCacheFile;
478-
479478
cached_database_path(State) ->
480479
case State#state.origin of
481480
{maxmind, EditionName} ->
@@ -878,15 +877,18 @@ extract_mmdb_from_tarball_blob(Tarball) ->
878877

879878
-spec has_mmdb_extension(nonempty_string()) -> boolean().
880879
has_mmdb_extension(Filename) ->
881-
has_extenstion(Filename, ["mmdb"]).
880+
has_extension(Filename, ["mmdb"]).
882881

883882
% Make sure the ExpectedExtensions list is passed in reverse order.
884883
% So if file is "archive.tar.gz", the ExpectedExtensions list is ["gz", "tar"].
885-
-spec has_extenstion(nonempty_string(), [nonempty_string()]) -> boolean().
886-
has_extenstion(Filename, ExpectedExtensions) ->
884+
-spec has_extension(file:filename_all(), [nonempty_string()]) -> boolean().
885+
has_extension(Filename, ExpectedExtensions) ->
887886
ExtensionParts = filename_extension_parts(Filename),
888887
lists:prefix(ExpectedExtensions, ExtensionParts).
889888

889+
filename_extension_parts(<<BinFilename/bytes>>) ->
890+
Filename = unicode:characters_to_list(BinFilename),
891+
filename_extension_parts_recur(Filename, []);
890892
filename_extension_parts(Filename) ->
891893
filename_extension_parts_recur(Filename, []).
892894

@@ -966,7 +968,7 @@ fetched_database_modification_datetime({cache, _}, #{modified_on := Modification
966968
fetched_database_modification_datetime({filesystem, _}, #{modified_on := ModificationDate}) ->
967969
ModificationDate.
968970

969-
%-spec make_cached_database_blob(nonempty_string(), binary()) -> binary().
971+
%-spec make_cached_database_blob(file:filename_all(), binary()) -> binary().
970972
make_cached_database_blob(CachedTarballPath, EncodedDatabase) ->
971973
?assertMatch(["gz", "mmdb" | _], filename_extension_parts(CachedTarballPath)),
972974
zlib:gzip(EncodedDatabase).

0 commit comments

Comments
 (0)