Skip to content

Commit ec71131

Browse files
authored
🔀 Merge pull request #24 from davep/invalid-mtime
Handle Windows throwing an OSError on dodgy mtime
2 parents 9c48c51 + 6992c80 commit ec71131

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# ChangeLog
22

3+
## Unreleased
4+
5+
**Released: WiP**
6+
7+
- Handled Windows throwing an `OSError` when `mtime` can't be adequately
8+
worked out.
9+
([6#issuecomment-2669234263](https://github.com/davep/textual-fspicker/issues/6#issuecomment-2669234263))
10+
311
## v0.2.0
412

513
**Released: 2025-01-30**

src/textual_fspicker/parts/directory_navigation.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,16 @@ def _mtime(location: Path) -> str:
9999
mtime = location.stat().st_mtime
100100
except FileNotFoundError:
101101
mtime = 0
102-
return datetime.fromtimestamp(int(mtime)).isoformat().replace("T", " ")
102+
try:
103+
mdatetime = datetime.fromtimestamp(int(mtime))
104+
except OSError:
105+
# It's possible, on Windows anyway, for the attempt to convert a
106+
# time like this to throw an OSError. So we'll capture that and
107+
# default to the epoch.
108+
#
109+
# https://github.com/davep/textual-fspicker/issues/6#issuecomment-2669234263
110+
mdatetime = datetime.fromtimestamp(0)
111+
return mdatetime.isoformat().replace("T", " ")
103112

104113
@staticmethod
105114
def _size(location: Path) -> str:

0 commit comments

Comments
 (0)