Skip to content

Commit f37b087

Browse files
committed
Refactor timestamp extraction in FsspecFilesSource
To allow sub-class customization
1 parent 612f57a commit f37b087

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/galaxy/files/sources/_fsspec.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,18 @@ def _to_filesystem_path(self, path: str) -> str:
215215
return path
216216

217217
def _extract_timestamp(self, info: dict) -> Optional[str]:
218-
"""Extract and format timestamp from fsspec file info."""
219-
# Handle timestamp fields more robustly - check for None explicitly
220-
mtime = info.get("mtime")
221-
if mtime is None:
222-
mtime = info.get("modified")
223-
if mtime is None:
224-
mtime = info.get("LastModified")
218+
"""Extract the timestamp from fsspec file info to use it in the RemoteFile entry.
225219
226-
ctime_result = self.to_dict_time(mtime)
227-
return ctime_result
220+
Subclasses can override this to customize timestamp extraction.
221+
By default, it tries to extract 'mtime', 'modified', or 'LastModified'
222+
"""
223+
return info.get("mtime") or info.get("modified") or info.get("LastModified")
224+
225+
def _get_formatted_timestamp(self, info: dict) -> Optional[str]:
226+
"""Get a formatted timestamp for the RemoteFile entry."""
227+
mtime = self._extract_timestamp(info)
228+
formatted_timestamp = self.to_dict_time(mtime)
229+
return formatted_timestamp
228230

229231
def _info_to_entry(self, info: dict) -> AnyRemoteEntry:
230232
"""Convert fsspec file info to Galaxy's remote entry format."""
@@ -237,7 +239,7 @@ def _info_to_entry(self, info: dict) -> AnyRemoteEntry:
237239
return RemoteDirectory(name=name, uri=uri, path=entry_path)
238240
else:
239241
size = int(info.get("size", 0))
240-
ctime = self._extract_timestamp(info)
242+
ctime = self._get_formatted_timestamp(info)
241243
return RemoteFile(name=name, size=size, ctime=ctime, uri=uri, path=entry_path)
242244

243245
def _list_recursive(self, fs: AbstractFileSystem, path: str) -> tuple[list[AnyRemoteEntry], int]:

0 commit comments

Comments
 (0)