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 19fc07b commit fef621b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/databricks/labs/blueprint/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ def _file_info(self) -> FileInfo:

def stat(self, *, follow_symlinks=True) -> os.stat_result:
seq: list[float] = [-1] * 10
seq[stat.ST_SIZE] = self._file_info.file_size or -1 # 6
seq[stat.ST_MTIME] = self._file_info.modification_time or -1 # 8
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
return os.stat_result(seq)

def is_dir(self) -> bool:
Expand Down Expand Up @@ -852,8 +852,8 @@ def _object_info(self) -> ObjectInfo:
def stat(self, *, follow_symlinks=True) -> os.stat_result:
seq: list[float] = [-1] * 10
seq[stat.ST_SIZE] = self._object_info.size or -1 # 6
seq[stat.ST_MTIME] = self._object_info.modified_at or -1 # 8
seq[stat.ST_CTIME] = self._object_info.created_at or -1 # 9
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
return os.stat_result(seq)

def is_dir(self) -> bool:
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import codecs
from datetime import datetime
from pathlib import Path

import pytest
Expand Down Expand Up @@ -67,6 +68,21 @@ def test_open_text_io(ws, make_random, cls):
assert not hello_txt.exists()


@pytest.mark.parametrize("cls", DATABRICKS_PATHLIKE)
def test_stat(ws, make_random, cls):
now = datetime.now().timestamp()
name = make_random()
wsp = cls(ws, f"~/{name}/a/b/c")
with_user = wsp.expanduser()
with_user.mkdir(parents=True)

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


@pytest.mark.parametrize("cls", DATABRICKS_PATHLIKE)
def test_unlink(ws, make_random, cls):
name = make_random()
Expand Down

0 comments on commit fef621b

Please sign in to comment.