|
| 1 | +from .. import filesystem |
1 | 2 | from ..asyn import AsyncFileSystem |
2 | 3 |
|
3 | 4 |
|
4 | 5 | class DirFileSystem(AsyncFileSystem): |
5 | | - def __init__(self, path, fs, *args, **storage_options): |
| 6 | + def __init__( |
| 7 | + self, |
| 8 | + path=None, |
| 9 | + fs=None, |
| 10 | + fo=None, |
| 11 | + target_protocol=None, |
| 12 | + target_options=None, |
| 13 | + **storage_options, |
| 14 | + ): |
6 | 15 | """ |
7 | 16 | Parameters |
8 | 17 | ---------- |
9 | 18 | path: str |
10 | 19 | Path to the directory. |
11 | 20 | fs: AbstractFileSystem |
12 | 21 | An instantiated filesystem to wrap. |
| 22 | + target_protocol, target_options: |
| 23 | + if fs is none, construct it from these |
| 24 | + fo: str |
| 25 | + Alternate for path; do not provide both |
13 | 26 | """ |
14 | | - super().__init__(*args, **storage_options) |
| 27 | + super().__init__(**storage_options) |
| 28 | + if fs is None: |
| 29 | + fs = filesystem(protocol=target_protocol, **(target_options or {})) |
| 30 | + if (path is not None) ^ (fo is not None) is False: |
| 31 | + raise ValueError("Provide path or fo, not both") |
| 32 | + path = path or fo |
15 | 33 |
|
16 | 34 | if self.asynchronous and not fs.async_impl: |
17 | 35 | raise ValueError("can't use asynchronous with non-async fs") |
@@ -198,20 +216,26 @@ def info(self, path, **kwargs): |
198 | 216 | return self.fs.info(self._join(path), **kwargs) |
199 | 217 |
|
200 | 218 | async def _ls(self, path, detail=True, **kwargs): |
201 | | - ret = await self.fs._ls(self._join(path), detail=detail, **kwargs) |
| 219 | + ret = (await self.fs._ls(self._join(path), detail=detail, **kwargs)).copy() |
202 | 220 | if detail: |
| 221 | + out = [] |
203 | 222 | for entry in ret: |
| 223 | + entry = entry.copy() |
204 | 224 | entry["name"] = self._relpath(entry["name"]) |
205 | | - return ret |
| 225 | + out.append(entry) |
| 226 | + return out |
206 | 227 |
|
207 | 228 | return self._relpath(ret) |
208 | 229 |
|
209 | 230 | def ls(self, path, detail=True, **kwargs): |
210 | | - ret = self.fs.ls(self._join(path), detail=detail, **kwargs) |
| 231 | + ret = self.fs.ls(self._join(path), detail=detail, **kwargs).copy() |
211 | 232 | if detail: |
| 233 | + out = [] |
212 | 234 | for entry in ret: |
| 235 | + entry = entry.copy() |
213 | 236 | entry["name"] = self._relpath(entry["name"]) |
214 | | - return ret |
| 237 | + out.append(entry) |
| 238 | + return out |
215 | 239 |
|
216 | 240 | return self._relpath(ret) |
217 | 241 |
|
|
0 commit comments