Skip to content
Snippets Groups Projects
Commit c2820634 authored by Jim MacArthur's avatar Jim MacArthur
Browse files

Virtual directory API: Add get_size with implementations

parent 3b7f115a
No related branches found
No related tags found
No related merge requests found
......@@ -836,6 +836,18 @@ class CasBasedDirectory(Directory):
self._recalculate_recursing_up()
self._recalculate_recursing_down()
def get_size(self):
total = len(self.pb2_directory.SerializeToString())
for i in self.index.values():
if isinstance(i.buildstream_object, CasBasedDirectory):
total += i.buildstream_object.get_size()
elif isinstance(i.pb_object, remote_execution_pb2.FileNode):
src_name = self.cas_cache.objpath(i.pb_object.digest)
filesize = os.stat(src_name).st_size
total += filesize
# Symlink nodes are encoded as part of the directory serialization.
return total
def _get_identifier(self):
path = ""
if self.parent:
......
......@@ -30,6 +30,7 @@ See also: :ref:`sandboxing`.
import os
import time
from .directory import Directory, VirtualDirectoryError
from .. import utils
from ..utils import link_files, copy_files, list_relative_paths, _get_link_mtime, _magic_timestamp
from ..utils import _set_deterministic_user, _set_deterministic_mtime
......@@ -201,6 +202,9 @@ class FileBasedDirectory(Directory):
return list_relative_paths(self.external_directory)
def get_size(self):
return utils._get_dir_size(self.external_directory)
def __str__(self):
# This returns the whole path (since we don't know where the directory started)
# which exposes the sandbox directory; we will have to assume for the time being
......
......@@ -176,3 +176,9 @@ class Directory():
"""
raise NotImplementedError()
def get_size(self):
""" Get an approximation of the storage space in bytes used by this directory
and all files and subdirectories in it. Storage space varies by implementation
and effective space used may be lower than this number due to deduplication. """
raise NotImplementedError()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment