Skip to content

Commit 2a23a1e

Browse files
Support modification time for S3 & Azure (#176)
* Support modification time for S3 * Add test case for Azure and fix implementaion to support Azure --------- Signed-off-by: Gayathri <[email protected]>
1 parent edbdb0c commit 2a23a1e

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/unstract/sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.62.0"
1+
__version__ = "0.62.1"
22

33

44
def get_sdk_version():

src/unstract/sdk/file_storage/impl.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,23 @@ def modification_time(self, path: str) -> datetime:
207207
datetime: Last modified time in datetime
208208
"""
209209
file_info = self.fs.info(path)
210-
file_mtime = file_info["mtime"]
211-
if not isinstance(file_mtime, datetime):
212-
file_mtime = datetime.fromtimestamp(file_mtime)
213-
return file_mtime
210+
211+
# Try different possible timestamp keys
212+
file_mtime = None
213+
for key in ["mtime", "LastModified", "last_modified"]:
214+
file_mtime = file_info.get(key)
215+
if file_mtime is not None:
216+
break
217+
218+
if file_mtime is None:
219+
raise FileOperationError(
220+
f"Could not find modification time in file info: {file_info}"
221+
)
222+
223+
if isinstance(file_mtime, datetime):
224+
return file_mtime
225+
226+
return datetime.fromtimestamp(file_mtime)
214227

215228
def mime_type(
216229
self,

tests/test_file_storage.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import io
23
import json
34
import os.path
@@ -358,6 +359,32 @@ def test_make_dir(file_storage, folder_path, expected_result):
358359
assert file_storage.exists(path=folder_path) == expected_result
359360

360361

362+
@pytest.mark.parametrize(
363+
"file_storage, folder_path",
364+
[
365+
(file_storage(provider=FileStorageProvider.GCS), TEST_CONSTANTS.READ_PDF_FILE),
366+
(
367+
file_storage(provider=FileStorageProvider.LOCAL),
368+
TEST_CONSTANTS.READ_TEXT_FILE,
369+
),
370+
(file_storage(provider=FileStorageProvider.S3), TEST_CONSTANTS.READ_TEXT_FILE),
371+
(
372+
file_storage(provider=FileStorageProvider.MINIO),
373+
TEST_CONSTANTS.READ_TEXT_FILE,
374+
),
375+
(
376+
file_storage(provider=FileStorageProvider.AZURE),
377+
TEST_CONSTANTS.READ_TEXT_FILE,
378+
),
379+
],
380+
)
381+
def test_modification_time(file_storage, folder_path):
382+
modification_time = file_storage.modification_time(path=folder_path)
383+
assert modification_time is not None and isinstance(
384+
modification_time, datetime.datetime
385+
)
386+
387+
361388
@pytest.mark.parametrize(
362389
"file_storage, folder_path, expected_result",
363390
[

0 commit comments

Comments
 (0)