Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dictionary): avoid overwrite corruption if filenames are the same #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

YodaEmbedding
Copy link

@YodaEmbedding YodaEmbedding commented Jul 25, 2024

Fixes #14.


Consider:

function M.update_dictionary_files(dictionaries)
	for lang, dict in pairs(dictionaries) do
		M.write(filename, table.concat(dict, "\n") .. "\n")
	end
end

This leads to file corruption if filenames are identical for different langs. For instance, lang = en-US and lang = en-GB will both write to a file named en.utf-8.add.

Also, while we're at it, let's also write the output in a deterministic order for people (like me) who save their dictionaries in version control:

table.sort(merged_list)

@YodaEmbedding YodaEmbedding force-pushed the pr/fix/dictionary-write-corruption branch from 57f87f8 to f290b5e Compare August 20, 2024 03:39
@YodaEmbedding YodaEmbedding force-pushed the pr/fix/dictionary-write-corruption branch from f290b5e to 3bd56d1 Compare August 20, 2024 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dictionary write corruption if same filename
1 participant