Repository navigation
Add property uri to every file controller #68
Description
Activity
path/url/uriacross the file controllers#158 adds
uribut leavespathandurlin place, so all three now name a location. Proposal for how they should relate, for discussion before anything is changed.uriis the read interface- Every controller answers
uriin the scheme of its own backend:file://for https://github.com/OpenSemanticLab/osw-python/blob/main/src/osw/controller/file/local.py,s3://forS3FileController,https://<domain>/wiki/File:...forWikiFileController,NoneforInMemoryController. uriis 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
uriand nothing else.
pathandurlstay, as backend-native handlesThey are not redundant with
uri, they are the inputuriis derived from, and each is the type its backend actually works with:LocalFileController.pathis apathlib.Pathand is used as a path, not as a string:src/osw/express.py:335,:367,:368. It is also part of the public return ofosw_download_file(...), which callers use to open the downloaded file.model.S3File.urlis a field of the wiki schema atCategory:OSWc43f749badcb4490a785505de1fc7d20, fetched at runtime by https://github.com/OpenSemanticLab/osw-python/blob/main/examples/file_upload_download.py#L22-L24. Renaming it is a schema change plus a jsondata migration on every existing S3File page, not a Python-only rename.WikiFileController.urlis already a derived property (https://github.com/OpenSemanticLab/osw-python/blob/main/src/osw/controller/file/wiki.py#L167), so there it isuriunder another name.
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
pathandurloutright would be a breaking change for a gain thaturialready delivers.Missing piece: the write side
urihas no counterpart for going the other way. Afrom_uri()classmethod onFileControllerthat 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 auri. That is what makesurian actual interchange format rather than a display string, and it givesfrom_other/put_froma way to start from a location instead of an already-built controller.Loose ends
model.RemoteFiledoes not declareurl, soRemoteFileController.urireturningself.urlrelies on a contract the subclasses happen to keep rather than one the base class states. DeclaringurlonRemoteFilewould fix that, again as a schema change.- The wiki controllers need credentials to build a
uri, sofrom_uriforhttps://cannot be a pure constructor. It needs anosworcred_mngrargument, unlike the local and S3 cases.
- Every controller answers
Originally posted by @simontaurus in #66 (comment)