Skip to content

Commit 18ab597

Browse files
Minimum viable code solution for ModTime in detail responses
See #105
1 parent b0617ba commit 18ab597

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/pelicanfs/core.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
import aiohttp
2727
import cachetools
2828
import fsspec.implementations.http as fshttp
29-
from aiowebdav2.client import Client
29+
from aiowebdav2.client import (
30+
Client,
31+
Urn,
32+
)
3033
from aiowebdav2.exceptions import (
3134
MethodNotSupportedError,
3235
RemoteResourceNotFoundError,
3336
ResponseErrorCodeError,
3437
)
38+
from aiowebdav2.parser import WebDavXmlUtils
3539
from fsspec.asyn import AsyncFileSystem, sync
3640
from fsspec.utils import glob_translate
3741

@@ -570,18 +574,33 @@ async def _ls_real(self, url, detail=True):
570574

571575
async def get_item_detail(item):
572576
full_path = f"{base_url}{item}"
573-
try:
574-
is_directory = await client.is_dir(item)
575-
type_ = "directory" if is_directory else "file"
576-
except MethodNotSupportedError as e:
577-
if getattr(e, "name", "") == "is_dir":
578-
type_ = "file"
579-
else:
580-
raise
577+
urn = Urn(item)
578+
path = client.get_full_path(urn)
579+
response = await client.execute_request(
580+
action="info",
581+
path=urn.path(),
582+
headers_ext=["Depth: 0"],
583+
)
584+
content = await response.read()
585+
is_directory = WebDavXmlUtils.parse_is_dir_response(
586+
content=content,
587+
path=path,
588+
hostname=client._url,
589+
)
590+
info = WebDavXmlUtils.parse_info_response(
591+
content=content,
592+
path=path,
593+
hostname=client._url,
594+
)
595+
import datetime
581596
return {
582597
"name": full_path,
583-
"size": None,
584-
"type": type_,
598+
"size": info["size"],
599+
"type": "directory" if is_directory else "file",
600+
"mod_time": datetime.datetime.strptime(
601+
info["modified"],
602+
"%a, %d %b %Y %H:%M:%S %Z",
603+
),
585604
}
586605

587606
return await asyncio.gather(*(get_item_detail(item) for item in items))

0 commit comments

Comments
 (0)