Bladeren bron

Add the ability to use `G` (GiB) and `T` (TiB) suffixes in configuration options that refer to numbers of bytes. (#16219)

* Add more suffixes to `parse_size`

* Newsfile

Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>

---------

Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
tags/v1.93.0rc1
reivilibre 8 maanden geleden
committed by GitHub
bovenliggende
commit
e937e2111a
Geen bekende sleutel gevonden voor deze handtekening in de database GPG sleutel-ID: 4AEE18F83AFDEB23
3 gewijzigde bestanden met toevoegingen van 8 en 4 verwijderingen
  1. +1
    -0
      changelog.d/16219.feature
  2. +3
    -1
      docs/usage/configuration/config_documentation.md
  3. +4
    -3
      synapse/config/_base.py

+ 1
- 0
changelog.d/16219.feature Bestand weergeven

@@ -0,0 +1 @@
Add the ability to use `G` (GiB) and `T` (TiB) suffixes in configuration options that refer to numbers of bytes.

+ 3
- 1
docs/usage/configuration/config_documentation.md Bestand weergeven

@@ -25,8 +25,10 @@ messages from the database after 5 minutes, rather than 5 months.


In addition, configuration options referring to size use the following suffixes: In addition, configuration options referring to size use the following suffixes:


* `M` = MiB, or 1,048,576 bytes
* `K` = KiB, or 1024 bytes * `K` = KiB, or 1024 bytes
* `M` = MiB, or 1,048,576 bytes
* `G` = GiB, or 1,073,741,824 bytes
* `T` = TiB, or 1,099,511,627,776 bytes


For example, setting `max_avatar_size: 10M` means that Synapse will not accept files larger than 10,485,760 bytes For example, setting `max_avatar_size: 10M` means that Synapse will not accept files larger than 10,485,760 bytes
for a user avatar. for a user avatar.


+ 4
- 3
synapse/config/_base.py Bestand weergeven

@@ -179,8 +179,9 @@ class Config:


If an integer is provided it is treated as bytes and is unchanged. If an integer is provided it is treated as bytes and is unchanged.


String byte sizes can have a suffix of 'K' or `M`, representing kibibytes and
mebibytes respectively. No suffix is understood as a plain byte count.
String byte sizes can have a suffix of 'K', `M`, `G` or `T`,
representing kibibytes, mebibytes, gibibytes and tebibytes respectively.
No suffix is understood as a plain byte count.


Raises: Raises:
TypeError, if given something other than an integer or a string TypeError, if given something other than an integer or a string
@@ -189,7 +190,7 @@ class Config:
if type(value) is int: # noqa: E721 if type(value) is int: # noqa: E721
return value return value
elif isinstance(value, str): elif isinstance(value, str):
sizes = {"K": 1024, "M": 1024 * 1024}
sizes = {"K": 1024, "M": 1024 * 1024, "G": 1024**3, "T": 1024**4}
size = 1 size = 1
suffix = value[-1] suffix = value[-1]
if suffix in sizes: if suffix in sizes:


Laden…
Annuleren
Opslaan