Skip to content

Add property uri to every file controller #68

Description

@simontaurus
          This should be implemented as `uri` in every file controller, even local files (see https://en.wikipedia.org/wiki/File_URI_scheme)

Originally posted by @simontaurus in #66 (comment)

Activity

  1. LukasGold commented on Sep 2, 2026

    @LukasGold
    Contributor

    path / url / uri across the file controllers

    #158 adds uri but leaves path and url in place, so all three now name a location. Proposal for how they should relate, for discussion before anything is changed.

    uri is the read interface

    • Every controller answers uri in the scheme of its own backend: file:// for https://github.com/OpenSemanticLab/osw-python/blob/main/src/osw/controller/file/local.py, s3:// for S3FileController, https://<domain>/wiki/File:... for WikiFileController, None for InMemoryController.
    • uri is derived on every access and never stored, so it cannot go stale when the underlying handle changes.
    • Callers that only want to know where a file lives, log it, compare two controllers, or hand a location to something else use uri and nothing else.

    path and url stay, as backend-native handles

    They are not redundant with uri, they are the input uri is derived from, and each is the type its backend actually works with:

    So the collapse happens at the interface, not in the storage: one name to read a location, the native handle kept where the backend needs it. Removing path and url outright would be a breaking change for a gain that uri already delivers.

    Missing piece: the write side

    uri has no counterpart for going the other way. A from_uri() classmethod on FileController that dispatches on the scheme would close that:

    FileController.from_uri("file:///tmp/a.txt")                    # -> LocalFileController
    FileController.from_uri("s3://bucket/key")                      # -> S3FileController
    FileController.from_uri("https://wiki.example.org/wiki/File:X") # -> WikiFileController

    with FileController.from_uri(c.uri) round-tripping for every controller that has a uri. That is what makes uri an actual interchange format rather than a display string, and it gives from_other / put_from a way to start from a location instead of an already-built controller.

    Loose ends

    • model.RemoteFile does not declare url, so RemoteFileController.uri returning self.url relies on a contract the subclasses happen to keep rather than one the base class states. Declaring url on RemoteFile would fix that, again as a schema change.
    • The wiki controllers need credentials to build a uri, so from_uri for https:// cannot be a pure constructor. It needs an osw or cred_mngr argument, unlike the local and S3 cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions