rustypaste icon indicating copy to clipboard operation
rustypaste copied to clipboard

feat: support `max_upload_dir_size` config

Open Narayanbhat166 opened this issue 1 year ago • 1 comments

Description

This Pull Request adds a feature to limit the uploads if the ./uploads dir is full. The size of ./uploads dir can be set by the config key max_upload_dir_size under the server config.

[server]
max_upload_dir_size = "100G"

Motivation and Context

This is required to restrict the number / size of uploads that can be made to the server when hosted publicly. This fixes #282

How Has This Been Tested?

Changelog Entry

  • Add a check for the max size of uploads directory

Types of Changes

  • [x] New feature (non-breaking change which adds functionality)

Checklist:

  • [x] My code follows the code style of this project.
  • [x] I have updated the documentation accordingly.
  • [x] I have formatted the code with rustfmt.
  • [x] I checked the lints with clippy.
  • [x] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

Narayanbhat166 avatar Aug 18 '24 11:08 Narayanbhat166

Let's get this over the finish line soon if possible :)

orhun avatar Sep 20 '24 19:09 orhun

Ping :)

orhun avatar Dec 07 '24 15:12 orhun

@Narayanbhat166 can you have a look and make the requested changes?

tessus avatar Dec 09 '24 13:12 tessus

Codecov Report

Attention: Patch coverage is 6.66667% with 28 lines in your changes missing coverage. Please review.

Project coverage is 80.51%. Comparing base (1d5a9c6) to head (aad5f77). Report is 29 commits behind head on master.

Files with missing lines Patch % Lines
src/util.rs 0.00% 17 Missing :warning:
src/paste.rs 15.38% 11 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #335      +/-   ##
==========================================
- Coverage   83.27%   80.51%   -2.76%     
==========================================
  Files          11       11              
  Lines        1214     1273      +59     
==========================================
+ Hits         1011     1025      +14     
- Misses        203      248      +45     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Dec 11 '24 11:12 codecov-commenter

@orhun I was just wondering what kind of perf impact this has. Isn't this similar to the duplicates=false issue? Every time there is an upload, all files have to be touched. Yes, getting the size of all files is probably a lot faster than calculating the hash for each file, but still. Patterns like this make me nervous, coming from a perf background.

tessus avatar Dec 11 '24 22:12 tessus

Yeah, probably the performance will be degrade in a noticeable way with this feature enabled.

I think we need to add benchmarks using hyperfine to get an idea about that. I did something similar for Zig in https://github.com/orhun/zig-http-benchmarks

orhun avatar Dec 12 '24 18:12 orhun