"""Round4 serving guard also detects same-timestamp/same-size source replacement."""
from .cluster_targets import digest
from .mask_taxonomy_source_guard import SourceGuard
from .pallet_description_round4_data import binding_guard as frozen_guard


class ContentSourceGuard(SourceGuard):
    def _token(self):
        # Some workspace/temp filesystems expose only second-resolution ctime.
        # Stat alone cannot establish that a same-size file is still the frozen bytes.
        return super()._token(),tuple((n,digest(self.project/n)) for n in sorted(self.expected_files))


def binding_guard():
    original=frozen_guard()
    try:
        return ContentSourceGuard(project=original.project,databases=original.databases,files=original.files,inventories=original.inventories,
            discover_databases=original.discover_databases,discover_inventories=original.discover_inventories,
            extra_databases=set(original.databases)-original.expected_databases,pinned_files=original.pinned_files)
    finally:original.close()
