Skip to content

Commit 0b60479

Browse files
Include extra info parameters in detail responses
Closes #105
1 parent b0617ba commit 0b60479

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

src/pelicanfs/core.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@
2121
import urllib.parse
2222
from contextlib import asynccontextmanager
2323
from copy import copy
24+
from datetime import datetime
2425
from typing import Dict, List, Optional, Tuple
2526

2627
import aiohttp
2728
import cachetools
2829
import fsspec.implementations.http as fshttp
29-
from aiowebdav2.client import Client
30+
from aiowebdav2.client import (
31+
Client,
32+
Urn,
33+
)
3034
from aiowebdav2.exceptions import (
3135
MethodNotSupportedError,
3236
RemoteResourceNotFoundError,
3337
ResponseErrorCodeError,
3438
)
39+
from aiowebdav2.parser import WebDavXmlUtils
3540
from fsspec.asyn import AsyncFileSystem, sync
3641
from fsspec.utils import glob_translate
3742

@@ -570,18 +575,44 @@ async def _ls_real(self, url, detail=True):
570575

571576
async def get_item_detail(item):
572577
full_path = f"{base_url}{item}"
578+
urn = Urn(item)
579+
path = client.get_full_path(urn)
580+
response = await client.execute_request(
581+
action="info",
582+
path=urn.path(),
583+
headers_ext=["Depth: 0"],
584+
)
585+
content = await response.read()
586+
587+
# determine directory status
573588
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
589+
is_directory = WebDavXmlUtils.parse_is_dir_response(
590+
content=content,
591+
path=path,
592+
hostname=client._url,
593+
)
594+
except MethodNotSupportedError:
595+
# If the server does not support the is_dir method, we assume it is a file
596+
is_directory = False
597+
598+
# get other info
599+
info = WebDavXmlUtils.parse_info_response(
600+
content=content,
601+
path=path,
602+
hostname=client._url,
603+
)
604+
if (modtimestr := info.get("modified")) == "None":
605+
modtime = None
606+
else:
607+
modtime = datetime.strptime(
608+
info["modified"],
609+
"%a, %d %b %Y %H:%M:%S %Z",
610+
)
581611
return {
582612
"name": full_path,
583-
"size": None,
584-
"type": type_,
613+
"size": int(info["size"]),
614+
"type": "directory" if is_directory else "file",
615+
"modified": modtime,
585616
}
586617

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

0 commit comments

Comments
 (0)