Skip to content

Commit

Permalink
Add quota-used-bytes and quota-available-bytes (RFC4331) (#277)
Browse files Browse the repository at this point in the history
* Add quota-used-bytes and quota-available-bytes

* Fix incorrect path to disk_usage

* Update CHANGELOG.md

Co-authored-by: Martin Wendt <mar10@wwwendt.de>
  • Loading branch information
NewbieOrange and mar10 committed Jan 8, 2023
1 parent 0bf23b0 commit a7a383d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## 4.1.1 / Unreleased
## 4.2.0 / Unreleased
- #277 Add quota-used-bytes and quota-available-bytes (RFC4331) (@NewbieOrange)

## 4.1.0 / 2022-11-11
- #246 Add dir_browser/htdocs folder setup.cfg (for install with `pip install .`)
Expand Down
26 changes: 26 additions & 0 deletions wsgidav/dav_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class _DAVResource(ABC):
get_creation_date()
get_display_name()
get_etag()
get_used_bytes()
get_available_bytes()
get_last_modified()
support_ranges()
Expand Down Expand Up @@ -278,6 +280,22 @@ def get_etag(self):
"""
return None

def get_used_bytes(self) -> Optional[int]:
"""Return used bytes of the DAV collection.
See http://www.webdav.org/specs/rfc4331.html#quota-used-bytes
This method COULD be implemented for collection resources.
"""
return None

def get_available_bytes(self) -> Optional[int]:
"""Return available bytes of the DAV collection.
See http://www.webdav.org/specs/rfc4331.html#quota-available-bytes
This method COULD be implemented for collection resources.
"""
return None

def get_last_modified(self):
"""Contains the Last-Modified header returned by a GET method without
accept headers.
Expand Down Expand Up @@ -531,6 +549,10 @@ def get_property_names(self, *, is_allprop):
propNameList.append("{DAV:}getcontentlength")
if self.get_content_type() is not None:
propNameList.append("{DAV:}getcontenttype")
if self.get_used_bytes() is not None:
propNameList.append("{DAV:}quota-used-bytes")
if self.get_available_bytes() is not None:
propNameList.append("{DAV:}quota-available-bytes")
if self.get_last_modified() is not None:
propNameList.append("{DAV:}getlastmodified")
if self.get_display_name() is not None:
Expand Down Expand Up @@ -706,6 +728,10 @@ def get_property_value(self, name):
etree.SubElement(resourcetypeEL, "{DAV:}collection")
return resourcetypeEL
return ""
elif name == "{DAV:}quota-used-bytes":
return self.get_used_bytes()
elif name == "{DAV:}quota-available-bytes":
return self.get_available_bytes()
elif (
name == "{DAV:}getlastmodified" and self.get_last_modified() is not None
):
Expand Down
6 changes: 6 additions & 0 deletions wsgidav/fs_dav_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ def get_directory_info(self):
def get_etag(self):
return None

def get_used_bytes(self):
return shutil.disk_usage(self._file_path).used

def get_available_bytes(self):
return shutil.disk_usage(self._file_path).free

def get_last_modified(self):
return self.file_stat[stat.ST_MTIME]

Expand Down

0 comments on commit a7a383d

Please sign in to comment.