Skip to content

Commit

Permalink
align with unix conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Sep 12, 2024
1 parent fef621b commit 785bb9a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/databricks/labs/blueprint/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,11 @@ def _file_info(self) -> FileInfo:
return self._cached_file_info

def stat(self, *, follow_symlinks=True) -> os.stat_result:
seq: list[float] = [-1] * 10
seq[stat.ST_SIZE] = float(self._file_info.file_size) / 1000.0 or -1 # 6
seq[stat.ST_MTIME] = float(self._file_info.modification_time) / 1000.0 or -1 # 8
seq: list[float] = [-1.0] * 10
seq[stat.ST_SIZE] = self._file_info.file_size or -1 # 6
seq[stat.ST_MTIME] = (
float(self._file_info.modification_time) / 1000.0 if self._file_info.modification_time else -1.0
) # 8
return os.stat_result(seq)

def is_dir(self) -> bool:
Expand Down Expand Up @@ -850,10 +852,12 @@ def _object_info(self) -> ObjectInfo:
return self._object_info

def stat(self, *, follow_symlinks=True) -> os.stat_result:
seq: list[float] = [-1] * 10
seq: list[float] = [-1.0] * 10
seq[stat.ST_SIZE] = self._object_info.size or -1 # 6
seq[stat.ST_MTIME] = float(self._object_info.modified_at) / 1000.0 or -1 # 8
seq[stat.ST_CTIME] = float(self._object_info.created_at) / 1000.0 or -1 # 9
seq[stat.ST_MTIME] = (
float(self._object_info.modified_at) / 1000.0 if self._object_info.modified_at else -1.0
) # 8
seq[stat.ST_CTIME] = float(self._object_info.created_at) / 1000.0 if self._object_info.created_at else -1.0 # 9
return os.stat_result(seq)

def is_dir(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_stat(ws, make_random, cls):

hello_txt = with_user / "hello.txt"
hello_txt.write_text("Hello, World!")
if cls is WorkspacePath: # DBFSPath has no st_ctime
if cls is WorkspacePath: # DBFSPath has no st_ctime
assert hello_txt.stat().st_ctime >= now
assert hello_txt.stat().st_mtime >= now

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,8 @@ def test_workspace_path_stat_has_fields():
ws.workspace.get_status.return_value = info
workspace_path = WorkspacePath(ws, "/test/path")
stats = workspace_path.stat()
assert stats.st_ctime == info.created_at
assert stats.st_mtime == info.modified_at
assert stats.st_ctime == info.created_at / 1000.0
assert stats.st_mtime == info.modified_at / 1000.0
assert stats.st_size == info.size


Expand All @@ -1027,5 +1027,5 @@ def test_dbfs_path_stat_has_fields():
ws.dbfs.get_status.return_value = info
dbfs_path = DBFSPath(ws, "/test/path")
stats = dbfs_path.stat()
assert stats.st_mtime == info.modification_time
assert stats.st_mtime == info.modification_time / 1000.0
assert stats.st_size == info.file_size

0 comments on commit 785bb9a

Please sign in to comment.