Skip to content

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

Open
YodaEmbedding wants to merge 2 commits into
jhofscheier:mainfrom
YodaEmbedding:pr/fix/dictionary-write-corruption
Open

fix(dictionary): avoid overwrite corruption if filenames are the same#15
YodaEmbedding wants to merge 2 commits into
jhofscheier:mainfrom
YodaEmbedding:pr/fix/dictionary-write-corruption

Conversation

@YodaEmbedding
Copy link
Copy Markdown
Contributor

@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