Skip to content

Commit ca41da3

Browse files
authored
Update viking_fs.py (#252)
fix bug ValueError: Invalid isoformat string on Windows due to high-precision timestamps #242
1 parent d2201b6 commit ca41da3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

openviking/storage/viking_fs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,19 @@ async def _ls_agent(
10041004
all_entries = []
10051005
for entry in entries:
10061006
name = entry.get("name", "")
1007+
# 修改后:通过截断字符串来兼容 7 位或更多位的微秒
1008+
raw_time = entry.get("modTime", "")
1009+
if raw_time and len(raw_time) > 26 and "+" in raw_time:
1010+
# 处理像 2026-02-21T13:20:23.1470042+08:00 这样的字符串
1011+
# 截断为 2026-02-21T13:20:23.147004+08:00
1012+
parts = raw_time.split("+")
1013+
# 保持时间部分最多 26 位 (YYYY-MM-DDTHH:MM:SS.mmmmmm)
1014+
raw_time = parts[0][:26] + "+" + parts[1]
10071015
new_entry = {
10081016
"uri": str(VikingURI(uri).join(name)),
10091017
"size": entry.get("size", 0),
10101018
"isDir": entry.get("isDir", False),
1011-
"modTime": format_simplified(datetime.fromisoformat(entry.get("modTime", "")), now),
1019+
"modTime": format_simplified(datetime.fromisoformat(raw_time), now),
10121020
}
10131021
if entry.get("isDir"):
10141022
all_entries.append(new_entry)

0 commit comments

Comments
 (0)