Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created October 17, 2008 19:37
Show Gist options
  • Save ngerakines/17508 to your computer and use it in GitHub Desktop.
Save ngerakines/17508 to your computer and use it in GitHub Desktop.
Determine the next binlog file for a given binlog filename.
-module(binlog).
-compile(export_all).
current_log() -> "db-000004.bin".
%% binlog:next_log(binlog:current_log()).
%% binlog:next_log("db-000004.bin").
next_log("db-" ++ TmpA) ->
"nib." ++ TmpB = lists:reverse(TmpA),
TmpC = list_to_integer(lists:reverse(TmpB)) + 1,
lists:concat(["db-", string:right(integer_to_list(TmpC), erlang:length(TmpB), $0), ".bin"]).
test_a_() ->
[
next_log("db-000000.bin") == "db-000001.bin",
next_log("db-000004.bin") == "db-000005.bin",
next_log("db-000008.bin") == "db-000009.bin",
next_log("db-000009.bin") == "db-000010.bin",
next_log("db-000304.bin") == "db-000305.bin",
next_log("db-003009.bin") == "db-003010.bin"
].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment