Proposal: Refactor `SiaPath` to always be absolute
Overview
Ever since the introduction of the new filesystem, the SiaPath
type has been in kind of a limbo. Sometimes it's an absolute path, sometimes it's a relative path and the only way to know is to pass around a flag.
Design or Proposal
Refactor the codebase to make sure the SiaPath
instance always contains an absolute SiaPath
. In fact I would get rid of NewSiaPath(string)
and hardcode the RootFolder
, BackupFolder
, SkynetFolder
and UserFolder
.
Then the only valid ways to create a SiaPath
is to do one of the following:
RootFolder.Join(string)
BackupFolder.Join(string)
SkynetFolder.Join(string)
UserFolder.Join(string)
and
RandomSiaPath()
for testing
The result is that no arbitrary SiaPath
s can be created anymore which will reduce developer errors and it will also reduce errors in the sense that a dev can confidently pass any SiaPath
to a method accepting a SiaPath
without having to think about whether it needs to be an absolute or relative one.
NOTE:
Obviously we need to stay compatible in the API. That's why I also suggest replacing the modules.SiaPath
in the API with an api.SiaPath
which contains some of the same checks as a regular modules.SiaPath
but which is only used within the API and has to be converted to a modules.SiaPath
before being used within the modules.