Resolve a virtual path, including symbolic links and directory references it might include. Path must not include circular symbolic links. Args: virtpath: virtual path to resolve, either relative or absolute Returns: An absolute virtual path
(self, virtpath: Union[str, AnyPurePath])
| 162 | |
| 163 | # this will work only if hosting os = virtual os |
| 164 | def __virtual_resolve(self, virtpath: Union[str, AnyPurePath]) -> AnyPurePath: |
| 165 | """Resolve a virtual path, including symbolic links and directory |
| 166 | references it might include. Path must not include circular symbolic |
| 167 | links. |
| 168 | |
| 169 | Args: |
| 170 | virtpath: virtual path to resolve, either relative or absolute |
| 171 | |
| 172 | Returns: An absolute virtual path |
| 173 | """ |
| 174 | |
| 175 | vpath = self.PureVirtualPath(virtpath) |
| 176 | |
| 177 | # if not already, turn vpath into an absolute path |
| 178 | if not vpath.is_absolute(): |
| 179 | vpath = self.__virtual_abspath(vpath) |
| 180 | |
| 181 | # accumulate paths as we progress through the resolution process. |
| 182 | # |
| 183 | # since symlink inspection and resolution can only be done on an |
| 184 | # actual file system, each step in the progress has to be translated |
| 185 | # into its correpsonding host path. that is the reason we keep track |
| 186 | # on the acumulated host path in parallel to the virtual one |
| 187 | # |
| 188 | # note: the reason we do not set acc_hpath to rootfs is to prevent |
| 189 | # parent dir refs from traversing beyond rootfs directory. |
| 190 | |
| 191 | acc_hpath = Path() |
| 192 | acc_vpath = self.PureVirtualPath(vpath.anchor) |
| 193 | |
| 194 | # eliminate virtual path's anchor to allow us accumulate its |
| 195 | # parts on top of rootfs |
| 196 | vpath = vpath.relative_to(vpath.anchor) |
| 197 | |
| 198 | for part in vpath.parts: |
| 199 | if part == '..': |
| 200 | acc_hpath = acc_hpath.parent |
| 201 | acc_vpath = acc_vpath.parent |
| 202 | |
| 203 | else: |
| 204 | # if this is a symlink attempt to resolve it |
| 205 | vtemp = self.__resolved_vsymlink(acc_hpath, part) |
| 206 | |
| 207 | # not a symlink; accumulate path part |
| 208 | if vtemp is None: |
| 209 | acc_hpath = acc_hpath / part |
| 210 | acc_vpath = acc_vpath / part |
| 211 | |
| 212 | else: |
| 213 | # rebase it on top of the accumulated virtual path |
| 214 | new_vpath = acc_vpath / vtemp |
| 215 | |
| 216 | # recursively resolve the new virtual path we got |
| 217 | vres = self.__virtual_resolve(new_vpath) |
| 218 | |
| 219 | acc_hpath = Path(vres) |
| 220 | acc_vpath = vres |
| 221 |
no test coverage detected