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

Use random module to produce an actually unique file name #30

Merged
merged 1 commit into from Oct 8, 2021

Conversation

Lukas0907
Copy link
Contributor

During tests I noticed that flask_mailman would not produce one log file per message but actually sometimes append a message to an existing mail log file. By looking at the code I noticed that the file name of the log is derived from the ID of the object which might be reused (see also https://stackoverflow.com/q/20753364/172822 for a discussion). To get a truly unique file name I changed the code so that randrange() is used.

Copy link
Contributor

@marktennyson marktennyson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an valueable observation and fix. But one thing I wondered to know, why you using random.randint ? Instead of this you can use the current timestamp using time.time().

@Lukas0907
Copy link
Contributor Author

But one thing I wondered to know, why you using random.randint ? Instead of this you can use the current timestamp using time.time().

What advantage would that have? The idea of the fix is that it's basically impossible to have two log files with the same name. That's not guaranteed with time.time().

@codecov
Copy link

codecov bot commented Oct 8, 2021

Codecov Report

Merging #30 (bce9272) into master (6558b3a) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #30      +/-   ##
==========================================
+ Coverage   63.03%   63.10%   +0.06%     
==========================================
  Files           9        9              
  Lines         579      580       +1     
==========================================
+ Hits          365      366       +1     
  Misses        214      214              
Impacted Files Coverage Δ
flask_mailman/backends/file.py 86.04% <100.00%> (+0.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6558b3a...bce9272. Read the comment docs.

@waynerv waynerv merged commit 91dcc8b into waynerv:master Oct 8, 2021
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.

None yet

3 participants